﻿using AutoTask.Model;
using BankDbHelper;
using ExcuteInterface;
using Jdwl.Api;
using Jdwl.Api.Domain.Clps.ClpsOpenGwService;
using Jdwl.Api.Request.Clps;
using Newtonsoft.Json;
using OpenApiSDK;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Threading.Tasks;

namespace AutoTask
{
    public class UpJob : IUpJob
    {
        JobLogger _jobLogger;
        public UpJob(JobLogger jobLogger)
        {
            _jobLogger = jobLogger;
        }
        private BankSqlHelper sqlHelper;
        private IJdClient client;
        private string serverUrl;
        private string accessToken;
        private string appKey;
        private string appSecret;
        private string Pin;
        private string wdgj_appkey;
        private string wdgj_appsecret;
        private string wdgj_accesstoken;
        private string createdate;
        public async Task<int> ExecJob(JobPara jobPara, List<Datas> dsData)
        {

            sqlHelper = jobPara.bankSqlHelper;
            serverUrl = dsData[0].DataMain.Rows[0].DataRowGetStringValue("serverUrl");
            accessToken = dsData[0].DataMain.Rows[0].DataRowGetStringValue("accessToken");
            appKey = dsData[0].DataMain.Rows[0].DataRowGetStringValue("appKey");
            appSecret = dsData[0].DataMain.Rows[0].DataRowGetStringValue("appSecret");
            Pin = dsData[0].DataMain.Rows[0].DataRowGetStringValue("Pin");
            wdgj_appkey = dsData[0].DataMain.Rows[0].DataRowGetStringValue("wdgj_appkey");
            wdgj_appsecret = dsData[0].DataMain.Rows[0].DataRowGetStringValue("wdgj_appsecret");
            wdgj_accesstoken = dsData[0].DataMain.Rows[0].DataRowGetStringValue("wdgj_accesstoken");
            createdate = jobPara.DbType == DBTypeEnum.Oracle ? "sysdate" : "getdate()";
            var result = jobPara.jobCode switch
            {
                "10001" => await SupplierInfo(jobPara, dsData),
                "10002" => await DrugInfo(jobPara, dsData),
                "20002" => await DrugInfo(jobPara, dsData),
               // "20001" => await QueryDrug(jobPara, dsData),
                "resetError" => await ResetError(jobPara, dsData),
                "10012" => await WdgjSupplier(jobPara, dsData),
                "10011" => await WdgjGoods(jobPara, dsData),
                "10010" => await OrderClose(jobPara, dsData),
                "10003" => await ShopInfo(jobPara, dsData),
                "10004" => await PurchaseOrder(jobPara, dsData),
               // "10005" => await QueryPurchase(jobPara, dsData),
                "10006" => await PurchaseReturn(jobPara, dsData),
               // "10007" => await QueryPurchaseReturn(jobPara, dsData),
                //"10008" => await QueryStock(jobPara, dsData),
                "10009" => await DBRK(jobPara, dsData),
                "10013" => await DBCK(jobPara, dsData),
                _ => -1,
            };
            return result;
        }

        /// <summary>
        /// 调拨出库
        /// </summary>
        /// <param name="jobPara"></param>
        /// <param name="dsData"></param>
        /// <returns></returns>
        public async Task<int> DBCK(JobPara jobPara, List<Datas> dsData)
        {
            try
            {
                if (string.IsNullOrEmpty(serverUrl) || string.IsNullOrEmpty(accessToken) || string.IsNullOrEmpty(appKey) || string.IsNullOrEmpty(appSecret) || string.IsNullOrEmpty(Pin))
                {
                    await _jobLogger.WriteLogAsync(LogType.Info, "调拨出库信息推送", $"失败:数据源中缺少serverUrl、accessToken、appKey、appSecret、Pin!");
                    return 0;
                }
                else
                {
                    client = new DefaultJdClient(serverUrl, accessToken, appKey, appSecret);
                }

                for (int i = 0; i < dsData.Count; i++)
                {
                    var OrderLines = new List<SoOrderLine>();
                    for (int j = 0; j < dsData[i].DataDetail[0].Rows.Count; j++)
                    {

                        OrderLines.Add(new SoOrderLine
                        {
                            OrderLineNo = dsData[i].DataDetail[0].Rows[j].DataRowGetStringValue("DETAILNO"),
                            SplitBoxNum = dsData[i].DataDetail[0].Rows[j].DataRowGetIntValue("SplitBoxNum"),
                            OnePackBox  = dsData[i].DataDetail[0].Rows[j].DataRowGetByteValue("OnePackBox"),
                            ItemId = dsData[i].DataDetail[0].Rows[j].DataRowGetStringValue("CLPSGOODSCODE"),
                            PlanQty = dsData[i].DataDetail[0].Rows[j].DataRowGetIntValue("QUANTITY"),
                            SerialNo = dsData[i].DataDetail[0].Rows[j].DataRowGetStringValue("SerialNo"),
                            ShopGoodsNo = dsData[i].DataDetail[0].Rows[j].DataRowGetStringValue("ShopGoodsNo"),
                            SourceOrderCode = dsData[i].DataDetail[0].Rows[j].DataRowGetStringValue("SourceOrderCode"),
                            SubSourceOrderCode = dsData[i].DataDetail[0].Rows[j].DataRowGetStringValue("SubSourceOrderCode"),
                            VirtualSuiteGoodsName = dsData[i].DataDetail[0].Rows[j].DataRowGetStringValue("VirtualSuiteGoodsName"),
                            VirtualSuiteGoodsNo = dsData[i].DataDetail[0].Rows[j].DataRowGetStringValue("VirtualSuiteGoodsNo"),
                            VirtualSuiteGoodsQty = dsData[i].DataDetail[0].Rows[j].DataRowGetIntValue("VirtualSuiteGoodsQty"),
                            ActualPrice = dsData[i].DataDetail[0].Rows[j].DataRowGetIntValue("ActualPrice"),
                            BatchCode = dsData[i].DataDetail[0].Rows[j].DataRowGetStringValue("BatchCode"),
                            DiscountAmount = dsData[i].DataDetail[0].Rows[j].DataRowGetIntValue("DiscountAmount"),
                            ExpireDate = dsData[i].DataDetail[0].Rows[j].DataRowGetStringValue("ExpireDate"),
                            ExtCode = dsData[i].DataDetail[0].Rows[j].DataRowGetStringValue("ExtCode"),
                            GoodsLevel = dsData[i].DataDetail[0].Rows[j].DataRowGetStringValue("GoodsLevel"),
                            InstallVenderId = dsData[i].DataDetail[0].Rows[j].DataRowGetStringValue("InstallVenderId"),
                            InventoryType = dsData[i].DataDetail[0].Rows[j].DataRowGetStringValue("InventoryType"),
                            ItemCode = dsData[i].DataDetail[0].Rows[j].DataRowGetStringValue("ItemCode"),
                            ItemName = dsData[i].DataDetail[0].Rows[j].DataRowGetStringValue("ItemName"),
                            ItemRemark = dsData[i].DataDetail[0].Rows[j].DataRowGetStringValue("ItemRemark"),
                            OutPackageNo = dsData[i].DataDetail[0].Rows[j].DataRowGetStringValue("OutPackageNo"),
                            PackageNo = dsData[i].DataDetail[0].Rows[j].DataRowGetStringValue("PackageNo"),
                            PayNo = dsData[i].DataDetail[0].Rows[j].DataRowGetStringValue("PayNo"),
                            PlanOutQty = dsData[i].DataDetail[0].Rows[j].DataRowGetStringValue("PlanOutQty"),
                            PrintName = dsData[i].DataDetail[0].Rows[j].DataRowGetStringValue("PrintName"),
                            ProductDate = dsData[i].DataDetail[0].Rows[j].DataRowGetStringValue("ProductDate"),
                            RetailPrice = dsData[i].DataDetail[0].Rows[j].DataRowGetIntValue("RetailPrice"),
                            UnitCode = dsData[i].DataDetail[0].Rows[j].DataRowGetStringValue("UnitCode"),
                            UnitName = dsData[i].DataDetail[0].Rows[j].DataRowGetStringValue("UnitName"),
                            UomQty = dsData[i].DataDetail[0].Rows[j].DataRowGetIntValue("UomQty"),
                            LotInfo = new LotInfo { 
                                BatAttrList = new List<BatAttr> {
                                    new BatAttr{
                                    BatchKey = "customBacthCode",
                                    BatchValue = dsData[i].DataDetail[0].Rows[j].DataRowGetStringValue("customBacthCode")
                                   },
                                   new BatAttr{
                                    BatchKey = "madedate",
                                    BatchValue = dsData[i].DataDetail[0].Rows[j].DataRowGetStringValue("madedate")
                                   },
                                   new BatAttr{
                                    BatchKey = "expiredate",
                                    BatchValue =dsData[i].DataDetail[0].Rows[j].DataRowGetStringValue("expiredate")
                                   }

                                },BatchQty = dsData[i].DataDetail[0].Rows[j].DataRowGetIntValue("BatchQty")
                            }
                        });
                    }

                    var request = new ClpsTransportSoOrderLopRequest
                    {
                        Pin = Pin,
                        Request = new SoCreateRequest
                        {
                            DeliveryOrder = new SoDeliveryOrder
                            {
                                DeliveryOrderCode = dsData[i].DataMain.Rows[0]["LSH"].SqlDataBankToString(),
                                IsvSource = dsData[i].DataMain.Rows[0]["IsvSource"].SqlDataBankToString(),
                                OrderType ="DBCK", //dsData[i].DataMain.Rows[0]["ORDERTYPE"].SqlDataBankToString(),
                                SoType = dsData[i].DataMain.Rows[0].DataRowGetStringValue("SoType") == "" ?"1": dsData[i].DataMain.Rows[0].DataRowGetStringValue("SoType"),
                                WarehouseCode = dsData[i].DataMain.Rows[0]["warehouseNo"].SqlDataBankToString(),
                                OrderMark = dsData[i].DataMain.Rows[0].DataRowGetStringValue("OrderMark"),
                                SourcePlatformCode = dsData[i].DataMain.Rows[0].DataRowGetStringValue("SourcePlatformCode") == "" ? "1" : dsData[i].DataMain.Rows[0].DataRowGetStringValue("SourcePlatformCode"),
                                OwnerNo = dsData[i].DataMain.Rows[0]["ownerCode"].SqlDataBankToString(),
                                ShopNo = dsData[i].DataMain.Rows[0]["ShopNo"].SqlDataBankToString(),
                                LogisticsCode = dsData[i].DataMain.Rows[0]["LogisticsCode"].SqlDataBankToString(),
                                ReceiverInfo = new ReceiverInfo
                                {
                                    Name = dsData[i].DataMain.Rows[0]["receiverName"].SqlDataBankToString(),
                                    Mobile = dsData[i].DataMain.Rows[0]["receiverMobile"].SqlDataBankToString(),
                                    DetailAddress = dsData[i].DataMain.Rows[0]["receiverAddr"].SqlDataBankToString()
                                },
                                SalesPlatformOrderNo = dsData[i].DataMain.Rows[0].DataRowGetStringValue("SalesPlatformOrderNo"),
                                SellerMessage = dsData[i].DataMain.Rows[0].DataRowGetStringValue("SellerMessage"),
                                SellerNick = dsData[i].DataMain.Rows[0].DataRowGetStringValue("SellerNick"),
                                SellerRemark = dsData[i].DataMain.Rows[0].DataRowGetStringValue("SellerRemark"),
                                SendMode = dsData[i].DataMain.Rows[0].DataRowGetByteValue("SendMode"),
                                SendWebsiteCode = dsData[i].DataMain.Rows[0].DataRowGetStringValue("SendWebsiteCode"),
                                SendWebsiteName = dsData[i].DataMain.Rows[0].DataRowGetStringValue("SendWebsiteName"),
                                ServiceFee = dsData[i].DataMain.Rows[0].DataRowGetDoubleValue("ServiceFee"),
                                Shipment = dsData[i].DataMain.Rows[0].DataRowGetStringValue("Shipment"),
                                ShopNick = dsData[i].DataMain.Rows[0].DataRowGetStringValue("ShopNick"),
                                SoSource = dsData[i].DataMain.Rows[0].DataRowGetStringValue("SoSource"),
                                SourcePlatformName = dsData[i].DataMain.Rows[0].DataRowGetStringValue("SourcePlatformName"),
                                SplitFlag = dsData[i].DataMain.Rows[0].DataRowGetStringValue("SplitFlag"),
                                StoreName = dsData[i].DataMain.Rows[0].DataRowGetStringValue("StoreName"),
                                StringAddress = dsData[i].DataMain.Rows[0].DataRowGetStringValue("StringAddress"),
                                FreshStockCache = dsData[i].DataMain.Rows[0].DataRowGetStringValue("FreshStockCache"),
                                IsvSoType = dsData[i].DataMain.Rows[0].DataRowGetStringValue("IsvSoType"),
                                ThirdSite= dsData[i].DataMain.Rows[0].DataRowGetStringValue("ThirdSite"),
                                TransactionSource = dsData[i].DataMain.Rows[0].DataRowGetStringValue("TransactionSource"),
                                AddrAnalysis = dsData[i].DataMain.Rows[0].DataRowGetStringValue("AddrAnalysis"),
                                AllowLack = dsData[i].DataMain.Rows[0].DataRowGetStringValue("AllowLack"),
                                AppointDeliveryTime = dsData[i].DataMain.Rows[0].DataRowGetStringValue("AppointDeliveryTime"),
                                ArAmount = dsData[i].DataMain.Rows[0].DataRowGetDoubleValue("ArAmount"),
                                BankAccount = dsData[i].DataMain.Rows[0].DataRowGetStringValue("BankAccount"),
                                BankName = dsData[i].DataMain.Rows[0].DataRowGetStringValue("BankName"),
                                BdOwnerNo = dsData[i].DataMain.Rows[0].DataRowGetStringValue("BdOwnerNo"),
                                BusinessType = dsData[i].DataMain.Rows[0].DataRowGetStringValue("BusinessType"),
                                BuyerMessage = dsData[i].DataMain.Rows[0].DataRowGetStringValue("BuyerMessage"),
                                BuyerNick = dsData[i].DataMain.Rows[0].DataRowGetStringValue("BuyerNick"),
                                CreateTime = dsData[i].DataMain.Rows[0].DataRowGetStringValue("CreateTime"),
                                CustomerNo = dsData[i].DataMain.Rows[0].DataRowGetStringValue("CustomerNo"),
                                DestinationCode = dsData[i].DataMain.Rows[0].DataRowGetStringValue("DestinationCode"),
                                DestinationName = dsData[i].DataMain.Rows[0].DataRowGetStringValue("DestinationName"),
                                DiscountAmount = dsData[i].DataMain.Rows[0].DataRowGetDoubleValue("DiscountAmount"),
                                ExpectDeliveryDate = dsData[i].DataMain.Rows[0].DataRowGetStringValue("ExpectDeliveryDate"),
                                ExpProductType = dsData[i].DataMain.Rows[0].DataRowGetStringValue("ExpProductType"),
                                ExpressCode = dsData[i].DataMain.Rows[0].DataRowGetStringValue("ExpressCode"),
                                Freight = dsData[i].DataMain.Rows[0].DataRowGetDoubleValue("Freight"),
                                GotAmount = dsData[i].DataMain.Rows[0].DataRowGetDoubleValue("GotAmount"),
                                InsuranceFlag = dsData[i].DataMain.Rows[0].DataRowGetByteValue("InsuranceFlag"),
                                InvoiceFlag = dsData[i].DataMain.Rows[0].DataRowGetByteValue("InvoiceFlag"),
                                IsColdChain = dsData[i].DataMain.Rows[0].DataRowGetByteValue("IsColdChain"),
                                IsUrgency = dsData[i].DataMain.Rows[0].DataRowGetByteValue("IsUrgency"),
                                ItemAmount = dsData[i].DataMain.Rows[0].DataRowGetDoubleValue("ItemAmount"),
                                LogisticsAreaCode = dsData[i].DataMain.Rows[0].DataRowGetStringValue("LogisticsAreaCode"),
                                LogisticsName = dsData[i].DataMain.Rows[0].DataRowGetStringValue("LogisticsName"),
                                MonthlyAccount = dsData[i].DataMain.Rows[0].DataRowGetStringValue("MonthlyAccount"),
                                MultiValue = dsData[i].DataMain.Rows[0].DataRowGetStringValue("MultiValue"),
                                OperateTime = dsData[i].DataMain.Rows[0].DataRowGetStringValue("OperateTime"),
                                OperatorCode = dsData[i].DataMain.Rows[0].DataRowGetStringValue("OperatorCode"),
                                OperatorName = dsData[i].DataMain.Rows[0].DataRowGetStringValue("OperatorName"),
                                OrderBatchNo = dsData[i].DataMain.Rows[0].DataRowGetStringValue("OrderBatchNo"),
                                OrderPriority = dsData[i].DataMain.Rows[0].DataRowGetStringValue("OrderPriority"),
                                OrderBatchQty = dsData[i].DataMain.Rows[0].DataRowGetStringValue("OrderBatchQty"),
                                PackageMark = dsData[i].DataMain.Rows[0].DataRowGetStringValue("PackageMark"),
                                PayNo = dsData[i].DataMain.Rows[0].DataRowGetStringValue("PayNo"),
                                PayTime = dsData[i].DataMain.Rows[0].DataRowGetStringValue("PayTime"),
                                PhoneNumber= dsData[i].DataMain.Rows[0].DataRowGetStringValue("PhoneNumber"),
                                PlaceOrderTime = dsData[i].DataMain.Rows[0].DataRowGetStringValue("PlaceOrderTime"),
                                PinAccount = dsData[i].DataMain.Rows[0].DataRowGetStringValue("PinAccount"),
                                PlanDeliveryTime = dsData[i].DataMain.Rows[0].DataRowGetStringValue("PlanDeliveryTime"),
                                PreDeliveryOrderCode = dsData[i].DataMain.Rows[0].DataRowGetStringValue("PreDeliveryOrderCode"),
                                PreDeliveryOrderId = dsData[i].DataMain.Rows[0].DataRowGetStringValue("PreDeliveryOrderId"),
                                ReceiveMode = dsData[i].DataMain.Rows[0].DataRowGetByteValue("ReceiveMode"),
                                Remark = dsData[i].DataMain.Rows[0].DataRowGetStringValue("Remark"),
                                ThirdPayment = dsData[i].DataMain.Rows[0].DataRowGetByteValue("ThirdPayment"),
                                ThirdWayBill = dsData[i].DataMain.Rows[0].DataRowGetStringValue("ThirdWayBill"),
                                TotalAmount = dsData[i].DataMain.Rows[0].DataRowGetDoubleValue("TotalAmount"),
                                Transport = dsData[i].DataMain.Rows[0].DataRowGetStringValue("Transport"),
                                WaybillRemark = dsData[i].DataMain.Rows[0].DataRowGetStringValue("WaybillRemark"),
                                AddedService = dsData[i].DataMain.Rows[0].DataRowGetStringValue("AddedService"),
                                HoldSign = dsData[i].DataMain.Rows[0].DataRowGetStringValue("HoldSign"),
                                TcCode = dsData[i].DataMain.Rows[0].DataRowGetStringValue("TcCode"),
                                TcName = dsData[i].DataMain.Rows[0].DataRowGetStringValue("TcName"),
                                StockLimit = dsData[i].DataMain.Rows[0].DataRowGetStringValue("StockLimit"),
                                DeliveryRequirements = new DeliveryRequirements
                                {
                                    CarType = dsData[i].DataMain.Rows[0].DataRowGetStringValue("CarType"),
                                    ScheduleDay = dsData[i].DataMain.Rows[0].DataRowGetStringValue("ScheduleDay"),
                                    ScheduleStartTime = dsData[i].DataMain.Rows[0].DataRowGetStringValue("ScheduleStartTime"),
                                    ScheduleType = dsData[i].DataMain.Rows[0].DataRowGetIntValue("ScheduleType"),
                                    DeliveryType = dsData[i].DataMain.Rows[0].DataRowGetStringValue("DeliveryType"),
                                    ScheduleEndTime = dsData[i].DataMain.Rows[0].DataRowGetStringValue("ScheduleEndTime")
                                },
                                Insurance = new Insurance
                                {
                                    Amount = dsData[i].DataMain.Rows[0].DataRowGetDoubleValue("InsuranceAmount"),
                                    Type = dsData[i].DataMain.Rows[0].DataRowGetByteValue("InsuranceType"),
                                },
                                Insured = new Insured { 
                                    InsuredFee = dsData[i].DataMain.Rows[0].DataRowGetDoubleValue("InsuredFeeInsuredFee"),
                                    InsuredPriceFlag = dsData[i].DataMain.Rows[0].DataRowGetByteValue("InsuredFeeInsuredPriceFlag"),
                                    InsuredValue = dsData[i].DataMain.Rows[0].DataRowGetDoubleValue("InsuredFeeInsuredValue")
                                }
                                //,
                                //SenderInfo = new SenderInfo { },
                                //DeliveryRequirements = new DeliveryRequirements { },
                                //Insurance = new Insurance { },
                                //Insured = new Insured { },
                                //Invoice = new Invoice { }
                            },
                            OrderLines = OrderLines
                        }
                    };
                    var jsonrequest = JsonConvert.SerializeObject(request);
                    //{"response":{"content":{"code":"1","createTime":"2020-04-09 14:11:02","entryOrderCode":"CPL4418047912171","flag":"success","message":"成功"}, "code":0}}
                    var response = client.Execute(request);
                    await _jobLogger.WriteLogAsync(LogType.Info, "调拨出库信息推送", $"入参：\r\n{jsonrequest},返回Json:\r\n{response.Body}");
                    DBCKDResponseBody returnValue = JsonConvert.DeserializeObject<DBCKDResponseBody>(response.Body);

                    if (returnValue.response == null)
                    {
                        await sqlHelper.ExecSqlAsync(dsData[i].AfterFailure);
                        await _jobLogger.WriteLogAsync(LogType.Info, "调拨出库信息推送", $"失败后执行语句:{dsData[i].AfterFailure}");
                        return -1;
                    }
                    if (returnValue.response.code == 0)
                    {
                        if (returnValue.response.content.flag == "success")
                        {
                            var insertresult = await sqlHelper.ExecSqlAsync($"insert into CKDBDZK_XH_JDWMS(LSH,SYNCDATE,DBRKCKDCODE,TYPE) values('{dsData[i].DataMain.Rows[0]["LSH"].SqlDataBankToString()}',{createdate},'{returnValue.response.content.deliveryOrderCode}','{dsData[i].DataMain.Rows[0]["ORDERTYPE"].SqlDataBankToString()}')");
                            if (string.IsNullOrEmpty(insertresult))
                            {
                                await sqlHelper.ExecSqlAsync(dsData[i].AfterSuccess);
                                await _jobLogger.WriteLogAsync(LogType.Info, "调拨出库信息推送", $"{dsData[i].DataMain.Rows[0]["LSH"].SqlDataBankToString()}推送成功!成功后执行语句:{dsData[i].AfterSuccess}");
                            }
                            else
                            {
                                await sqlHelper.ExecSqlAsync($"insert into ERRORDATA_XH_JDWMS(GUID,ERRORNO,ERRORTYPE,MAINFIELD,ERRORDATE,ERRORMSG) values('{Guid.NewGuid():N}',{dsData[i].DataMain.Rows[0]["LSH"].SqlDataBankToString()},'dbckd','LSH',{createdate},'{returnValue.response.content.message}')");
                              
                                await _jobLogger.WriteLogAsync(LogType.Info, "调拨出库信息推送", $"{dsData[i].DataMain.Rows[0]["LSH"].SqlDataBankToString()}推送失败，失败原因:\r\n{returnValue.response.content.message + insertresult}");
                            }
                        }
                        else
                        {
                            await sqlHelper.ExecSqlAsync($"insert into ERRORDATA_XH_JDWMS(GUID,ERRORNO,ERRORTYPE,MAINFIELD,ERRORDATE,ERRORMSG) values('{Guid.NewGuid():N}',{dsData[i].DataMain.Rows[0]["LSH"].SqlDataBankToString()},'dbckd','LSH',{createdate},'{returnValue.response.content.message}')");
                            await sqlHelper.ExecSqlAsync(dsData[i].AfterFailure);
                            await _jobLogger.WriteLogAsync(LogType.Info, "调拨出库信息推送", $"{dsData[i].DataMain.Rows[0]["LSH"].SqlDataBankToString()}推送失败，失败原因:\r\n{returnValue.response.content.message},失败后执行语句:{dsData[i].AfterFailure}");
                        }
                    }
                    else
                    {
                        await sqlHelper.ExecSqlAsync(dsData[i].AfterFailure);
                        await _jobLogger.WriteLogAsync(LogType.Info, "调拨出库信息推送", $"{dsData[i].DataMain.Rows[0]["LSH"].SqlDataBankToString()}推送失败，返回值:\r\n{JsonConvert.SerializeObject(response)},失败后执行语句:{dsData[i].AfterFailure}");
                    }

                }
                return 0;
            }
            catch (Exception ex)
            {
                await _jobLogger.WriteLogAsync(LogType.Info, "调拨出库信息推送", $"失败，\r\n{ex.Message}");
                return -1;
            }
            finally
            {
                sqlHelper.Dispose();
            }
        }

        /// <summary>
        /// 调拨入库
        /// </summary>
        /// <param name="jobPara"></param>
        /// <param name="dsData"></param>
        /// <returns></returns>
        public async Task<int> DBRK(JobPara jobPara, List<Datas> dsData)
        {
            try
            {
                if (string.IsNullOrEmpty(serverUrl) || string.IsNullOrEmpty(accessToken) || string.IsNullOrEmpty(appKey) || string.IsNullOrEmpty(appSecret) || string.IsNullOrEmpty(Pin))
                {
                    await _jobLogger.WriteLogAsync(LogType.Info, "调拨入库信息推送", $"失败:数据源中缺少serverUrl、accessToken、appKey、appSecret、Pin!");
                    return -1;

                }
                else
                {
                    client = new DefaultJdClient(serverUrl, accessToken, appKey, appSecret);
                }
                for (int i = 0; i < dsData.Count; i++)
                {
                    var OrderLines = new List<PoItemModel>();
                    for (int j = 0; j < dsData[i].DataDetail[0].Rows.Count; j++)
                    {
                        OrderLines.Add(new PoItemModel
                        {
                            OrderLineNo = dsData[i].DataDetail[0].Rows[j].DataRowGetStringValue("DETAILNO"),
                            ItemNo = dsData[i].DataDetail[0].Rows[j].DataRowGetStringValue("CLPSGOODSCODE"),
                            PlanQty = dsData[i].DataDetail[0].Rows[j].DataRowGetIntValue("QUANTITY"),
                            GoodsStatus = dsData[i].DataDetail[0].Rows[j].DataRowGetStringValue("GoodsStatus") == "" ? "1" : dsData[i].DataDetail[0].Rows[j].DataRowGetStringValue("GoodsStatus"),
                            ProduceCode = dsData[i].DataDetail[0].Rows[j].DataRowGetStringValue("ProduceCode"),
                            ItemId = dsData[i].DataDetail[0].Rows[j].DataRowGetStringValue("CLPSGOODSCODE"),
                            SidCheckout = dsData[i].DataDetail[0].Rows[j].DataRowGetByteValue("SidCheckout"),
                            SkuProperty = dsData[i].DataDetail[0].Rows[j].DataRowGetStringValue("SkuProperty"),
                            PlanQtyStr = dsData[i].DataDetail[0].Rows[j].DataRowGetStringValue("PlanQtyStr"),
                            PackageSort = dsData[i].DataDetail[0].Rows[j].DataRowGetIntValue("PackageSort"),
                            BarCodeType = dsData[i].DataDetail[0].Rows[j].DataRowGetStringValue("BarCodeType"),
                            DetailNo = dsData[i].DataDetail[0].Rows[j].DataRowGetStringValue("DetailNo"),
                            ItemAmount = dsData[i].DataDetail[0].Rows[j].DataRowGetStringValue("ItemAmount"),
                            ItemPrice = dsData[i].DataDetail[0].Rows[j].DataRowGetStringValue("ItemPrice"),
                            BatchCode = dsData[i].DataDetail[0].Rows[j].DataRowGetStringValue("BatchCode"),
                            OutBizCode = dsData[i].DataDetail[0].Rows[j].DataRowGetStringValue("OutBizCode"),
                            ExpireDate = dsData[i].DataDetail[0].Rows[j].DataRowGetStringValue("ExpireDate"),
                            OwnerPackCode = dsData[i].DataDetail[0].Rows[j].DataRowGetStringValue("OwnerPackCode"),
                            PackageUnit = dsData[i].DataDetail[0].Rows[j].DataRowGetStringValue("PackageUnit"),
                            QualityCheckRate = dsData[i].DataDetail[0].Rows[j].DataRowGetStringValue("QualityCheckRate"),
                            InventoryType = dsData[i].DataDetail[0].Rows[j].DataRowGetStringValue("InventoryType"),
                            ItemName = dsData[i].DataDetail[0].Rows[j].DataRowGetStringValue("ItemName"),
                            ProductDate = dsData[i].DataDetail[0].Rows[j].DataRowGetStringValue("ProductDate"),
                            RetailPrice = dsData[i].DataDetail[0].Rows[j].DataRowGetStringValue("RetailPrice"),
                            PoBatch = new PoBatch {
                                BatchNo = dsData[i].DataDetail[0].Rows[j].DataRowGetStringValue("customBacthCode"),
                                BatAttrList = new List<BatAttr> {
                               new BatAttr{
                                BatchKey = "customBacthCode",
                                BatchValue = dsData[i].DataDetail[0].Rows[j].DataRowGetStringValue("customBacthCode")
                               },
                               new BatAttr{
                                BatchKey = "madedate",
                                BatchValue = dsData[i].DataDetail[0].Rows[j].DataRowGetStringValue("madedate")
                               },
                               new BatAttr{
                                BatchKey = "expiredate",
                                BatchValue =dsData[i].DataDetail[0].Rows[j].DataRowGetStringValue("expiredate")
                               }
                                }
                            }
                        });
                    }

                    var request = new ClpsAddPoOrderLopRequest
                    {
                        Pin = Pin,
                        PoAddRequest = new PoAddRequest
                        {
                            EntryOrder = new PoModel
                            {
                                EntryOrderCode = dsData[i].DataMain.Rows[0].DataRowGetStringValue("LSH"),
                                OwnerCode = dsData[i].DataMain.Rows[0].DataRowGetStringValue("ownerCode"),
                                SupplierCode = dsData[i].DataMain.Rows[0].DataRowGetStringValue("SupplierCode"),
                                WarehouseCode = dsData[i].DataMain.Rows[0].DataRowGetStringValue("warehouseNo"),
                                SupplierName = dsData[i].DataMain.Rows[0].DataRowGetStringValue("SupplierName"),
                                ExpectStartTime = dsData[i].DataMain.Rows[0].DataRowGetStringValue("ExpectStartTime"),
                                PoSign = dsData[i].DataMain.Rows[0].DataRowGetByteValue("PoSign"),
                                AcceptUnQcFlag = dsData[i].DataMain.Rows[0].DataRowGetStringValue("AcceptUnQcFlag"),
                                BillType = dsData[i].DataMain.Rows[0].DataRowGetStringValue("BillType"),
                                BoxFlag = dsData[i].DataMain.Rows[0].DataRowGetStringValue("BoxFlag"),
                                CustomsInfo = dsData[i].DataMain.Rows[0].DataRowGetStringValue("CustomsInfo"),
                                EdiRemark = dsData[i].DataMain.Rows[0].DataRowGetStringValue("EdiRemark"),
                                EffectiveDate = dsData[i].DataMain.Rows[0].DataRowGetStringValue("EffectiveDate"),
                                ExpectEndTime = dsData[i].DataMain.Rows[0].DataRowGetStringValue("ExpectEndTime"),
                                Incomplete = dsData[i].DataMain.Rows[0].DataRowGetByteValue("Incomplete"),
                                IsWithListBill = dsData[i].DataMain.Rows[0].DataRowGetByteValue("IsWithListBill"),
                                ListBillURL = dsData[i].DataMain.Rows[0].DataRowGetStringValue("ListBillURL"),
                                LogisticsCode = dsData[i].DataMain.Rows[0].DataRowGetStringValue("LogisticsCode"),
                                OrderAmount = dsData[i].DataMain.Rows[0].DataRowGetStringValue("OrderAmount"),
                                OrderCreateTime = dsData[i].DataMain.Rows[0].DataRowGetStringValue("OrderCreateTime"),
                                OrderMark = dsData[i].DataMain.Rows[0].DataRowGetStringValue("OrderMark"),
                                PoReturnMode = dsData[i].DataMain.Rows[0].DataRowGetByteValue("PoReturnMode"),
                                PurchaseOrderCode = dsData[i].DataMain.Rows[0].DataRowGetStringValue("PurchaseOrderCode"),
                                ReceiveLevel = dsData[i].DataMain.Rows[0].DataRowGetByteValue("ReceiveLevel"),
                                Remark = dsData[i].DataMain.Rows[0].DataRowGetStringValue("BdOwnerNo"),
                                UnitFlag = dsData[i].DataMain.Rows[0].DataRowGetByteValue("UnitFlag"),
                                UnitRule = dsData[i].DataMain.Rows[0].DataRowGetStringValue("UnitRule"),
                                WmsRemark = dsData[i].DataMain.Rows[0].DataRowGetStringValue("WmsRemark"),
                                CustomerNo = dsData[i].DataMain.Rows[0].DataRowGetStringValue("CustomerNo"),
                                ExpressCode = dsData[i].DataMain.Rows[0].DataRowGetStringValue("ExpressCode"),
                                LogisticsName = dsData[i].DataMain.Rows[0].DataRowGetStringValue("LogisticsName"),
                                OperateTime = dsData[i].DataMain.Rows[0].DataRowGetStringValue("OperateTime"),
                                OperatorCode = dsData[i].DataMain.Rows[0].DataRowGetStringValue("OperatorCode"),
                                OperatorName = dsData[i].DataMain.Rows[0].DataRowGetStringValue("OperatorName"),
                                IsPorterTeam = dsData[i].DataMain.Rows[0].DataRowGetByteValue("IsPorterTeam"),
                                AllowLack = dsData[i].DataMain.Rows[0].DataRowGetBoolValue("AllowLack"),
                                OrderType = "DBRK"//dsData[i].DataMain.Rows[0]["ORDERTYPE"].SqlDataBankToString()
                            },
                            OrderLines = OrderLines
                        }
                    };
                    var jsonrequest = JsonConvert.SerializeObject(request);
                    //{"response":{"content":{"code":"1","createTime":"2020-04-09 14:11:02","entryOrderCode":"CPL4418047912171","flag":"success","message":"成功"}, "code":0}}
                    var response = client.Execute(request);
                    await _jobLogger.WriteLogAsync(LogType.Info, "调拨入库信息推送", $"入参：\r\n{jsonrequest},返回Json:\r\n{response.Body}");
                    //如果请求执行正确,从这里获取强类型返回值
                    OrderResponseBody returnValue = JsonConvert.DeserializeObject<OrderResponseBody>(response.Body);

                    if (returnValue.response == null)
                    {
                        await sqlHelper.ExecSqlAsync(dsData[i].AfterFailure);
                        await _jobLogger.WriteLogAsync(LogType.Info, "调拨入库信息推送", $"失败后执行语句:{dsData[i].AfterFailure}");
                        return -1;
                    }
                    if (returnValue.response.code == 0)
                    {
                        if (returnValue.response.content.flag == "success")
                        {
                            //save rtsorderstatus to STOCKRETURNAPPROVE_XH_JDWMS table
                            var insertresult = await sqlHelper.ExecSqlAsync($"insert into CKDBDZK_XH_JDWMS(LSH,SYNCDATE,DBRKCKDCODE,TYPE) values('{dsData[i].DataMain.Rows[0]["LSH"].SqlDataBankToString()}',{createdate},'{returnValue.response.content.entryOrderCode}','{dsData[i].DataMain.Rows[0]["ORDERTYPE"].SqlDataBankToString()}')");
                            if (string.IsNullOrEmpty(insertresult))
                            {
                                await sqlHelper.ExecSqlAsync(dsData[i].AfterSuccess);
                                await _jobLogger.WriteLogAsync(LogType.Info, "调拨入库信息推送", $"{dsData[i].DataMain.Rows[0]["LSH"].SqlDataBankToString()}推送成功!成功后执行语句:{dsData[i].AfterSuccess}");
                            }
                            else
                            {
                                await sqlHelper.ExecSqlAsync($"insert into ERRORDATA_XH_JDWMS(GUID,ERRORNO,ERRORTYPE,MAINFIELD,ERRORDATE,ERRORMSG) values('{Guid.NewGuid():N}',{dsData[i].DataMain.Rows[0]["LSH"].SqlDataBankToString()},'dbrkd','LSH',{createdate},'{returnValue.response.content.message}')");

                                await _jobLogger.WriteLogAsync(LogType.Info, "调拨入库信息推送", $"{dsData[i].DataMain.Rows[0]["LSH"].SqlDataBankToString()}推送失败，失败原因:\r\n{returnValue.response.content.message + insertresult}");
                            }

                        }
                        else
                        {
                            await sqlHelper.ExecSqlAsync($"insert into ERRORDATA_XH_JDWMS(GUID,ERRORNO,ERRORTYPE,MAINFIELD,ERRORDATE,ERRORMSG) values('{Guid.NewGuid():N}',{dsData[i].DataMain.Rows[0]["LSH"].SqlDataBankToString()},'dbrkd','LSH',{createdate},'{returnValue.response.content.message}')");
                            await sqlHelper.ExecSqlAsync(dsData[i].AfterFailure);
                            await _jobLogger.WriteLogAsync(LogType.Info, "调拨入库信息推送", $"{dsData[i].DataMain.Rows[0]["LSH"].SqlDataBankToString()}推送失败，失败原因:\r\n{returnValue.response.content.message},失败后执行语句:{dsData[i].AfterFailure}");
                        }


                    }
                    //响应的原始报文,如果请求失败,从这里获取错误消息代码
                    else
                    {
                        await sqlHelper.ExecSqlAsync(dsData[i].AfterFailure);
                        await _jobLogger.WriteLogAsync(LogType.Info, "调拨入库信息推送", $"{dsData[i].DataMain.Rows[0]["LSH"].SqlDataBankToString()}推送失败，返回值:\r\n{JsonConvert.SerializeObject(response)},失败后执行语句:{dsData[i].AfterFailure}");
                    }

                }
                return 0;
            }
            catch (Exception ex)
            {
                await _jobLogger.WriteLogAsync(LogType.Info, "调拨入库信息推送", $"失败，\r\n{ex.Message}");
                return -1;
            }
            finally
            {
                sqlHelper.Dispose();
            }
        }

        /// <summary>
        /// 查询库存
        /// </summary>
        /// <param name="jobPara"></param>
        /// <param name="dsData"></param>
        /// <returns></returns>
        //public async Task<int> QueryStock(JobPara jobPara, List<Datas> dsData)
        //{
        //    try
        //    {


        //        if (string.IsNullOrEmpty(serverUrl) || string.IsNullOrEmpty(accessToken) || string.IsNullOrEmpty(appKey) || string.IsNullOrEmpty(appSecret) || string.IsNullOrEmpty(Pin))
        //        {
        //            await _jobLogger.WriteLogAsync(LogType.Info, "查询库存信息", $"失败:数据源中缺少serverUrl、accessToken、appKey、appSecret、Pin!");
        //            return -1;

        //        }
        //        else
        //        {
        //            client = new DefaultJdClient(serverUrl, accessToken, appKey, appSecret);
        //        }
        //        for (int i = 0; i < dsData.Count; i++)
        //        {
        //            var request = new ClpsQueryStockLopRequest
        //            {
        //                Pin = Pin,
        //                QueryWarehouseStockRequest = new QueryWarehouseStockRequest
        //                {
        //                    WarehouseNo = dsData[i].DataMain.Rows[0]["warehouseNo"].SqlDataBankToString(),
        //                    OwnerNo = dsData[i].DataMain.Rows[0]["ownerCode"].SqlDataBankToString(),
        //                    GoodsNo = dsData[i].DataMain.Rows[0]["CLPSGOODSCODE"].SqlDataBankToString(),
        //                    CurrentPage = 1,
        //                    PageSize = 1
        //                }
        //            };
        //            var jsonrequest = JsonConvert.SerializeObject(request);


        //            //{"response":{"content":{"code":"1","flag":"success","message":"成功","totalLines":1,"warehouseStockModelList":[{"goodsName":"耳聋左慈丸","goodsNo":"CMG4418287716460","ownerName":"GXW测试货主勿动","ownerNo":"CBU8816093026319","sellerGoodsSign":"00000001","stockStatus":"1","stockType":"1","totalNum":2000,"totalNumValue":2000.0,"usableNum":2000,"usableNumValue":2000.0,"warehouseName":"GXWj接口测试仓","warehouseNo":"800001801"}]}, "code":0}}
        //            var response = client.Execute(request);
        //            await _jobLogger.WriteLogAsync(LogType.Info, "查询库存信息", $"入参：\r\n{jsonrequest},返回Json:\r\n{response.Body}");
        //            //如果请求执行正确,从这里获取强类型返回值
        //            QueryStockResponseBody returnValue = JsonConvert.DeserializeObject<QueryStockResponseBody>(response.Body);
        //            if (returnValue.response.code == 0)
        //            {
        //                //save rtsorderstatus to STOCKRETURNAPPROVE_XH_JDWMS table
        //                var insertresult = await sqlHelper.ExecSqlAsync($"update YW_KCK_XH_JDWMS set JDWMSSTOCK = '{returnValue.response.content.warehouseStockModelList[0].UsableNum}' where HH ='{dsData[i].DataMain.Rows[0]["HH"].SqlDataBankToString()}'");
        //                if (string.IsNullOrEmpty(insertresult))
        //                {
        //                    await _jobLogger.WriteLogAsync(LogType.Info, "查询库存信息", $"{dsData[i].DataMain.Rows[0]["HH"].SqlDataBankToString()}成功");
        //                }
        //                else
        //                {
        //                    await _jobLogger.WriteLogAsync(LogType.Info, "查询库存信息", $"{dsData[i].DataMain.Rows[0]["HH"].SqlDataBankToString()}失败,原因:{insertresult}");
        //                }
        //            }
        //            //响应的原始报文,如果请求失败,从这里获取错误消息代码
        //            else
        //            {
        //                await _jobLogger.WriteLogAsync(LogType.Info, "查询库存信息", $"失败返回:{JsonConvert.SerializeObject(response)}");
        //            }

        //        }
        //        return 0;
        //    }
        //    catch (Exception ex)
        //    {
        //        await _jobLogger.WriteLogAsync(LogType.Info, "查询库存信息", $"失败，\r\n{ex.Message}");
        //        return -1;
        //    }
        //    finally
        //    {
        //        sqlHelper.Dispose();
        //    }
        //}

        /// <summary>
        /// 查询采购退单
        /// </summary>
        /// <param name="jobPara"></param>
        /// <param name="dsData"></param>
        /// <returns></returns>
        //public async Task<int> QueryPurchaseReturn(JobPara jobPara, List<Datas> dsData)
        //{
        //    try
        //    {

        //        if (string.IsNullOrEmpty(serverUrl) || string.IsNullOrEmpty(accessToken) || string.IsNullOrEmpty(appKey) || string.IsNullOrEmpty(appSecret) || string.IsNullOrEmpty(Pin))
        //        {
        //            await _jobLogger.WriteLogAsync(LogType.Info, "查询采购退单", $"失败:数据源中缺少serverUrl、accessToken、appKey、appSecret、Pin!");
        //            return -1;

        //        }
        //        else
        //        {
        //            client = new DefaultJdClient(serverUrl, accessToken, appKey, appSecret);
        //        }
        //        for (int i = 0; i < dsData.Count; i++)
        //        {
        //            string billno = dsData[i].DataMain.Rows[0]["CLPSRTSNO"].SqlDataBankToString();
        //            var request = new ClpsIsvRtsQueryLopRequest
        //            {
        //                Pin = Pin,
        //                QueryRtsOrderRequest = new QueryRtsOrderRequest
        //                {
        //                    RtsOrderNos = billno,
        //                    OwnerNo = dsData[i].DataMain.Rows[0]["ownerCode"].SqlDataBankToString()
        //                }
        //            };
        //            var jsonrequest = JsonConvert.SerializeObject(request);

        //            //{"response":{"content":{"code":"1","flag":"success","message":"成功","rtsResults":[{"deliveryMode":"1","isvRtsCode":"201909090001","operatorTime":"2020-04-07 17:05:31","operatorUser":"romensfzl","ownerNo":"CBU8816093026319","receiverInfo":{"email":"数据为null","mobile":"0578-5082404","name":"宋志强测试供应商"},"rtsCode":"CBS4418046753361","rtsDetailList":[{"goodsStatus":"1","itemId":"CMG4418288906048","itemName":"布洛伪麻胶囊(得尔)","itemNo":"00000007","planOutQty":5.0,"planQty":5}],"rtsOrderStatus":"100","serialNumberList":[],"source":"9","supplierNo":"CMS4418046523757","warehouseNo":"800001573"}],"totalLine":1}, "code":0}}
        //            var response = client.Execute(request);
        //            await _jobLogger.WriteLogAsync(LogType.Info, "查询采购退单", $"入参：\r\n{jsonrequest},返回Json:\r\n{response.Body}");
        //            //如果请求执行正确,从这里获取强类型返回值
        //            RtsOrderQueryResponseBody returnValue = JsonConvert.DeserializeObject<RtsOrderQueryResponseBody>(response.Body);
        //            if (returnValue.response.code == 0)
        //            {
        //                //save rtsorderstatus to STOCKRETURNAPPROVE_XH_JDWMS table
        //                var insertresult = await sqlHelper.ExecSqlAsync($"update STOCKRETURNAPPROVE_XH_JDWMS set RTSORDERSTATUS = '{returnValue.response.content.rtsResults[0].rtsOrderStatus }' where BILLNO ='{dsData[i].DataMain.Rows[0]["BILLNO"].SqlDataBankToString()}'");
        //                if (string.IsNullOrEmpty(insertresult))
        //                {
        //                    await _jobLogger.WriteLogAsync(LogType.Info, "查询采购退单", $"{dsData[i].DataMain.Rows[0]["BILLNO"].SqlDataBankToString()}成功");
        //                }
        //                else
        //                {
        //                    await _jobLogger.WriteLogAsync(LogType.Info, "查询采购退单", $"查询采购退单{dsData[i].DataMain.Rows[0]["BILLNO"].SqlDataBankToString()}失败,原因:{insertresult}");
        //                }
        //            }
        //            //响应的原始报文,如果请求失败,从这里获取错误消息代码
        //            else
        //            {
        //                await _jobLogger.WriteLogAsync(LogType.Info, "查询采购退单", $"返回:{JsonConvert.SerializeObject(response)}");
        //            }

        //        }
        //        return 0;
        //    }
        //    catch (Exception ex)
        //    {
        //        await _jobLogger.WriteLogAsync(LogType.Info, "查询采购退单", $"失败:{ex.Message}");
        //        return -1;
        //    }
        //    finally
        //    {
        //        sqlHelper.Dispose();
        //    }

        //}

        /// <summary>
        /// 采购退单
        /// </summary>
        /// <param name="jobPara"></param>
        /// <param name="dsData"></param>
        /// <returns></returns>
        public async Task<int> PurchaseReturn(JobPara jobPara, List<Datas> dsData)
        {
            try
            {
                if (string.IsNullOrEmpty(serverUrl) || string.IsNullOrEmpty(accessToken) || string.IsNullOrEmpty(appKey) || string.IsNullOrEmpty(appSecret) || string.IsNullOrEmpty(Pin))
                {
                    await _jobLogger.WriteLogAsync(LogType.Info, "调拨出库信息推送", $"失败:数据源中缺少serverUrl、accessToken、appKey、appSecret、Pin!");
                    return -1;

                }
                else
                {
                    client = new DefaultJdClient(serverUrl, accessToken, appKey, appSecret);
                }
                //dsData[i].DataDetail[0] 这个第i个是根据数据源中写的
                for (int i = 0; i < dsData.Count; i++)
                {
                    var RtsOrderItemList = new List<RtsOrderItem>();

                    //取商品明细
                    for (int j = 0; j < dsData[i].DataDetail[0].Rows.Count; j++)
                    {
                        var LotInfoList = new List<LotInfo>();
                        //取批次明细
                        //取批次明细中与商品相关的批次列表
                        var picByHH = dsData[i].DataDetail[1].AsEnumerable().Where(t=>t.Field<string>("hh")== dsData[i].DataDetail[0].Rows[j]["hh"].SqlDataBankToString()).CopyToDataTable();
                        for (int k = 0; k < picByHH.Rows.Count; k++)
                        {
                            LotInfoList.Add(
                                new LotInfo {
                                    BatAttrList = new List<BatAttr> {
                                       new BatAttr{
                                        BatchKey = "customBacthCode",
                                        BatchValue = picByHH.Rows[k].DataRowGetStringValue("customBacthCode")
                                       },
                                       new BatAttr{
                                        BatchKey = "madedate",
                                        BatchValue = picByHH.Rows[k].DataRowGetStringValue("madedate")
                                       },
                                       new BatAttr{
                                        BatchKey = "expiredate",
                                        BatchValue =picByHH.Rows[k].DataRowGetStringValue("expiredate")
                                       }
                                    }
                                    , BatchQty = picByHH.Rows[k].DataRowGetIntValue("BatchQty")
                                }
                            );
                        }
                        RtsOrderItemList.Add(new RtsOrderItem
                        {

                            ItemId = dsData[i].DataDetail[0].Rows[j].DataRowGetStringValue("CLPSGOODSCODE"),
                            ItemQty = dsData[i].DataDetail[0].Rows[j].DataRowGetIntValue("QUANTITY"),
                            LotInfoList = LotInfoList,
                            ItemCode = dsData[i].DataDetail[0].Rows[j].DataRowGetStringValue("ItemCode"),
                            ItemOutQty = dsData[i].DataDetail[0].Rows[j].DataRowGetStringValue("ItemOutQty")
                        });
                    }


                    

                    var request = new ClpsAddRtsOrderLopRequest
                    {
                        Pin = Pin,
                        RtsOrderRequest = new RtsOrderRequest
                        {
                            OwnerCode = dsData[i].DataMain.Rows[0].DataRowGetStringValue("ownerCode"),
                            OutRtsOrderCode = dsData[i].DataMain.Rows[0].DataRowGetStringValue("BILLNO"),
                            WarehouseCode = dsData[i].DataMain.Rows[0].DataRowGetStringValue("warehouseNo"),
                            ExtractionWay = dsData[i].DataMain.Rows[0].DataRowGetByteValue("ExtractionWay")==sbyte.Parse("0")? sbyte.Parse("1") : dsData[i].DataMain.Rows[0].DataRowGetByteValue("ExtractionWay"),
                            RtsOrderType = dsData[i].DataMain.Rows[0].DataRowGetByteValue("RtsOrderType"),
                            PackFlag = dsData[i].DataMain.Rows[0].DataRowGetStringValue("PackFlag"),
                            SupplierNo = dsData[i].DataMain.Rows[0].DataRowGetStringValue("SUPPLIERCODE"),
                            ReceiverInfo = new ReceiverInfo
                            {
                                Mobile = dsData[i].DataMain.Rows[0].DataRowGetStringValue("TEL"),
                                DetailAddress = dsData[i].DataMain.Rows[0].DataRowGetStringValue("DetailAddress"),
                                City = dsData[i].DataMain.Rows[0].DataRowGetStringValue("City"),
                                Company = dsData[i].DataMain.Rows[0].DataRowGetStringValue("Company"),
                                Area = dsData[i].DataMain.Rows[0].DataRowGetStringValue("Area"),
                                CountryCode = dsData[i].DataMain.Rows[0].DataRowGetStringValue("CountryCode"),
                                Email = dsData[i].DataMain.Rows[0].DataRowGetStringValue("Email"),
                                Name = dsData[i].DataMain.Rows[0].DataRowGetStringValue("Name"),
                                Province = dsData[i].DataMain.Rows[0].DataRowGetStringValue("Province"),
                                Remark = dsData[i].DataMain.Rows[0].DataRowGetStringValue("Remark"),
                                Tel = dsData[i].DataMain.Rows[0].DataRowGetStringValue("Tel"),
                                Town = dsData[i].DataMain.Rows[0].DataRowGetStringValue("Town"),
                                ZipCode = dsData[i].DataMain.Rows[0].DataRowGetStringValue("ZipCode")
                            },
                            //出库单明细
                            RtsOrderItemList = RtsOrderItemList
                        }
                    };
                    var jsonrequest = JsonConvert.SerializeObject(request);
                    //{"response":{"content":{"clpsRtsNo":"CBS4418046753361","code":"1","flag":"success","message":"成功"}, "code":0}}
                    var response = client.Execute(request);
                    await _jobLogger.WriteLogAsync(LogType.Info, "推送采购退单", $"入参：\r\n{jsonrequest},返回Json:\r\n{response.Body}");
                    //如果请求执行正确,从这里获取强类型返回值
                    RtsOrderResponseBody returnValue = JsonConvert.DeserializeObject<RtsOrderResponseBody>(response.Body);

                    if (returnValue.response == null)
                    {
                        await sqlHelper.ExecSqlAsync(dsData[i].AfterFailure);
                        await _jobLogger.WriteLogAsync(LogType.Info, "推送采购退单", $"失败后执行语句:{dsData[i].AfterFailure}");
                        return -1;
                    }
                    if (returnValue.response.code == 0)
                    {
                        if (returnValue.response.content.flag == "success")
                        {
                            var insertresult = await sqlHelper.ExecSqlAsync($"insert into STOCKRETURNAPPROVE_XH_JDWMS(BILLNO,SYNCDATE,CLPSRTSNO) values('{ dsData[i].DataMain.Rows[0]["BILLNO"].SqlDataBankToString()}',{createdate},'{returnValue.response.content.clpsRtsNo}')");
                            if (string.IsNullOrEmpty(insertresult))
                            {
                                await sqlHelper.ExecSqlAsync(dsData[i].AfterSuccess);
                                await _jobLogger.WriteLogAsync(LogType.Info, "推送采购退单", $"{dsData[i].DataMain.Rows[0]["BILLNO"].SqlDataBankToString()}成功,成功后执行语句:{dsData[i].AfterSuccess}");
                            }
                            else
                            {
                                await sqlHelper.ExecSqlAsync($"insert into ERRORDATA_XH_JDWMS(GUID,ERRORNO,ERRORTYPE,MAINFIELD,ERRORDATE,ERRORMSG) values('{Guid.NewGuid():N}',{dsData[i].DataMain.Rows[0]["BILLNO"].SqlDataBankToString()},'cgtd','CODE',{createdate},'{returnValue.response.content.message}')");
                                await _jobLogger.WriteLogAsync(LogType.Info, "推送采购退单", $"{dsData[i].DataMain.Rows[0]["BILLNO"].SqlDataBankToString()}失败,原因:{returnValue.response.content.message + insertresult}");
                            }
                        }
                        else
                        {
                            await sqlHelper.ExecSqlAsync($"insert into ERRORDATA_XH_JDWMS(GUID,ERRORNO,ERRORTYPE,MAINFIELD,ERRORDATE,ERRORMSG) values('{Guid.NewGuid():N}',{dsData[i].DataMain.Rows[0]["BILLNO"].SqlDataBankToString()},'cgtd','CODE',{createdate},'{returnValue.response.content.message}')");
                            await sqlHelper.ExecSqlAsync(dsData[i].AfterFailure);
                            await _jobLogger.WriteLogAsync(LogType.Info, "推送采购退单", $"{dsData[i].DataMain.Rows[0]["BILLNO"].SqlDataBankToString()}失败,原因:{returnValue.response.content.message},失败后执行语句:{dsData[i].AfterFailure}");
                        }
                    }
                    //响应的原始报文,如果请求失败,从这里获取错误消息代码
                    else
                    {
                        await sqlHelper.ExecSqlAsync(dsData[i].AfterFailure);
                        await _jobLogger.WriteLogAsync(LogType.Info, "推送采购退单", $"失败,返回:{JsonConvert.SerializeObject(response)},失败后执行语句:{dsData[i].AfterFailure}");
                    }

                }
                return 0;
            }
            catch (Exception ex)
            {
                await _jobLogger.WriteLogAsync(LogType.Info, "推送采购退单", $"失败,返回:{ex.Message}");
                return -1;
            }
            finally
            {
                sqlHelper.Dispose();
            }
        }

        /// <summary>
        /// 查询采购订单
        /// </summary>
        /// <param name="jobPara"></param>
        /// <param name="dsData"></param>
        /// <returns></returns>
        //public async Task<int> QueryPurchase(JobPara jobPara, List<Datas> dsData)
        //{
        //    try
        //    {

        //        if (string.IsNullOrEmpty(serverUrl) || string.IsNullOrEmpty(accessToken) || string.IsNullOrEmpty(appKey) || string.IsNullOrEmpty(appSecret) || string.IsNullOrEmpty(Pin))
        //        {
        //            await _jobLogger.WriteLogAsync(LogType.Info, "查询采购订单信息", $"失败:数据源中缺少serverUrl、accessToken、appKey、appSecret、Pin!");
        //            return -1;

        //        }
        //        else
        //        {
        //            client = new DefaultJdClient(serverUrl, accessToken, appKey, appSecret);
        //        }
        //        for (int i = 0; i < dsData.Count; i++)
        //        {
        //            string billno = dsData[i].DataMain.Rows[0]["BILLNO"].SqlDataBankToString();
        //            var request = new ClpsQueryPoOrderLopRequest
        //            {
        //                Pin = Pin,
        //                PoQueryRequest = new PoQueryRequest
        //                {
        //                    EntryOrderCode = billno,
        //                    OwnerCode = dsData[i].DataMain.Rows[0]["ownerCode"].SqlDataBankToString(),
        //                    WarehouseCode = dsData[i].DataMain.Rows[0]["warehouseNo"].SqlDataBankToString()
        //                }
        //            };
        //            var jsonrequest = JsonConvert.SerializeObject(request);
        //            var response = client.Execute(request);
        //            //{ "response":{ "content":{ "code":"1","entryOrder":{ "clpsOrderCode":"CPL4418047893011","createTime":"2020-04-03 13:40","createUser":"romensfzl","entryOrderCode":"201709250002","ownerCode":"CBU8816093026319","poOrderStatus":"20","supplierCode":"CMS4418046522447","warehouseCode":"800001801"},"flag":"success","message":"成功","poBoxModels":[],"serialNumberList":[],"totalLines":0}, "code":0}}

        //            await _jobLogger.WriteLogAsync(LogType.Info, "查询采购订单信息", $"入参：\r\n{jsonrequest},返回Json:\r\n{response.Body}");
        //            //如果请求执行正确,从这里获取强类型返回值
        //            OrderQueryResponseBody returnValue = JsonConvert.DeserializeObject<OrderQueryResponseBody>(response.Body);
        //            if (returnValue.response.code == 0)
        //            {

        //                var insertresult = await sqlHelper.ExecSqlAsync($"update STOCKORDERFORM_XH_JDWMS set POORDERSTATUS ={returnValue.response.content.entryOrder.poOrderStatus},STORAGESTATUS={returnValue.response.content.entryOrder.storageStatus} where BILLNO ='{dsData[i].DataMain.Rows[0]["BILLNO"].SqlDataBankToString()}'");
        //                if (string.IsNullOrEmpty(insertresult))
        //                {
        //                    await _jobLogger.WriteLogAsync(LogType.Info, "查询采购订单信息", $"{dsData[i].DataMain.Rows[0]["BILLNO"].SqlDataBankToString()}成功");
        //                }
        //                else
        //                {
        //                    await _jobLogger.WriteLogAsync(LogType.Info, "查询采购订单信息", $"{dsData[i].DataMain.Rows[0]["BILLNO"].SqlDataBankToString()}失败,原因:{insertresult}");
        //                }
        //            }
        //            //响应的原始报文,如果请求失败,从这里获取错误消息代码
        //            else
        //            {
        //                await _jobLogger.WriteLogAsync(LogType.Info, "查询采购订单信息", $"失败返回:{JsonConvert.SerializeObject(response)}");
        //            }

        //        }
        //        return 0;
        //    }
        //    catch (Exception ex)
        //    {
        //        await _jobLogger.WriteLogAsync(LogType.Info, "查询采购订单信息", $"失败返回:{ ex.Message}");
        //        return -1;
        //    }
        //    finally
        //    {
        //        sqlHelper.Dispose();
        //    }
        //}

        /// <summary>
        /// 推送采购订单
        /// </summary>
        /// <param name="jobPara"></param>
        /// <param name="dsData"></param>
        /// <returns></returns>
        public async Task<int> PurchaseOrder(JobPara jobPara, List<Datas> dsData)
        {

            if (string.IsNullOrEmpty(serverUrl) || string.IsNullOrEmpty(accessToken) || string.IsNullOrEmpty(appKey) || string.IsNullOrEmpty(appSecret) || string.IsNullOrEmpty(Pin))
            {
                await _jobLogger.WriteLogAsync(LogType.Info, "推送采购订单信息", $"失败:数据源中缺少serverUrl、accessToken、appKey、appSecret、Pin!");
                return -1;

            }
            else
            {
                client = new DefaultJdClient(serverUrl, accessToken, appKey, appSecret);
            }
            //dsData[i].DataDetail[0] the i is detail what developer defined
            for (int i = 0; i < dsData.Count; i++)
            {
                try
                {
                    var OrderLines = new List<PoItemModel>();

                    for (int j = 0; j < dsData[i].DataDetail[0].Rows.Count; j++)
                    {
                        OrderLines.Add(new PoItemModel
                        {
                            OrderLineNo = dsData[i].DataDetail[0].Rows[j].DataRowGetStringValue("DETAILNO"),
                            ItemNo = dsData[i].DataDetail[0].Rows[j].DataRowGetStringValue("CLPSGOODSCODE"),
                            PlanQty = dsData[i].DataDetail[0].Rows[j].DataRowGetIntValue("QUANTITY"),
                            GoodsStatus = dsData[i].DataDetail[0].Rows[j].DataRowGetStringValue("GoodsStatus") =="" ? "1": dsData[i].DataDetail[0].Rows[j].DataRowGetStringValue("GoodsStatus"),
                            ItemPrice = dsData[i].DataDetail[0].Rows[j].DataRowGetStringValue("ItemPrice"),
                            ItemAmount = dsData[i].DataDetail[0].Rows[j].DataRowGetStringValue("ItemAmount"),
                            ItemId = dsData[i].DataDetail[0].Rows[j].DataRowGetStringValue("CLPSGOODSCODE"),
                            SidCheckout = dsData[i].DataDetail[0].Rows[j].DataRowGetByteValue("SidCheckout"),
                            SkuProperty = dsData[i].DataDetail[0].Rows[j].DataRowGetStringValue("SkuProperty"),
                            PlanQtyStr = dsData[i].DataDetail[0].Rows[j].DataRowGetStringValue("PlanQtyStr"),
                            PackageSort = dsData[i].DataDetail[0].Rows[j].DataRowGetIntValue("PackageSort"),
                            BarCodeType = dsData[i].DataDetail[0].Rows[j].DataRowGetStringValue("BarCodeType"),
                            DetailNo = dsData[i].DataDetail[0].Rows[j].DataRowGetStringValue("DetailNo"),
                            RetailPrice = dsData[i].DataDetail[0].Rows[j].DataRowGetStringValue("RetailPrice"),
                            BatchCode = dsData[i].DataDetail[0].Rows[j].DataRowGetStringValue("BatchCode"),
                            OutBizCode = dsData[i].DataDetail[0].Rows[j].DataRowGetStringValue("OutBizCode"),
                            ExpireDate = dsData[i].DataDetail[0].Rows[j].DataRowGetStringValue("ExpireDate"),
                            OwnerPackCode = dsData[i].DataDetail[0].Rows[j].DataRowGetStringValue("OwnerPackCode"),
                            PackageUnit = dsData[i].DataDetail[0].Rows[j].DataRowGetStringValue("PackageUnit"),
                            QualityCheckRate = dsData[i].DataDetail[0].Rows[j].DataRowGetStringValue("QualityCheckRate"),
                            InventoryType = dsData[i].DataDetail[0].Rows[j].DataRowGetStringValue("InventoryType"),
                            ItemName = dsData[i].DataDetail[0].Rows[j].DataRowGetStringValue("ItemName"),
                            ProductDate = dsData[i].DataDetail[0].Rows[j].DataRowGetStringValue("ProductDate"),
                            ProduceCode = dsData[i].DataDetail[0].Rows[j].DataRowGetStringValue("ProduceCode")
                        });
                    }

                    var request = new ClpsAddPoOrderLopRequest
                    {
                        Pin = Pin,
                        PoAddRequest = new PoAddRequest
                        {
                            EntryOrder = new PoModel
                            {
                                EntryOrderCode = dsData[i].DataMain.Rows[0].DataRowGetStringValue("BILLNO"),
                                
                                OwnerCode = dsData[i].DataMain.Rows[0].DataRowGetStringValue("ownerCode"),
                                //京东那边的供应商编码
                                SupplierCode = dsData[i].DataMain.Rows[0].DataRowGetStringValue("SupplierCode"),
                                WarehouseCode = dsData[i].DataMain.Rows[0].DataRowGetStringValue("warehouseNo"),
                                OrderType = "CGRK",
                                SupplierName = dsData[i].DataMain.Rows[0].DataRowGetStringValue("SupplierName"),
                                ExpectStartTime = dsData[i].DataMain.Rows[0].DataRowGetStringValue("ExpectStartTime"),
                                PoSign = dsData[i].DataMain.Rows[0].DataRowGetByteValue("PoSign"),
                                AcceptUnQcFlag = dsData[i].DataMain.Rows[0].DataRowGetStringValue("AcceptUnQcFlag"),
                                BillType = dsData[i].DataMain.Rows[0].DataRowGetStringValue("BillType"),
                                BoxFlag = dsData[i].DataMain.Rows[0].DataRowGetStringValue("BoxFlag"),
                                CustomsInfo = dsData[i].DataMain.Rows[0].DataRowGetStringValue("CustomsInfo"),
                                EdiRemark = dsData[i].DataMain.Rows[0].DataRowGetStringValue("EdiRemark"),
                                EffectiveDate = dsData[i].DataMain.Rows[0].DataRowGetStringValue("EffectiveDate"),
                                ExpectEndTime = dsData[i].DataMain.Rows[0].DataRowGetStringValue("ExpectEndTime"),
                                Incomplete = dsData[i].DataMain.Rows[0].DataRowGetByteValue("Incomplete"),
                                IsWithListBill = dsData[i].DataMain.Rows[0].DataRowGetByteValue("IsWithListBill"),
                                ListBillURL = dsData[i].DataMain.Rows[0].DataRowGetStringValue("ListBillURL"),
                                LogisticsCode = dsData[i].DataMain.Rows[0].DataRowGetStringValue("LogisticsCode"),
                                OrderCreateTime = dsData[i].DataMain.Rows[0].DataRowGetStringValue("OrderCreateTime"),
                                OrderMark = dsData[i].DataMain.Rows[0].DataRowGetStringValue("OrderMark"),
                                PoReturnMode = dsData[i].DataMain.Rows[0].DataRowGetByteValue("PoReturnMode"),
                                PurchaseOrderCode = dsData[i].DataMain.Rows[0].DataRowGetStringValue("PurchaseOrderCode"),
                                ReceiveLevel = dsData[i].DataMain.Rows[0].DataRowGetByteValue("ReceiveLevel"),
                                Remark = dsData[i].DataMain.Rows[0].DataRowGetStringValue("BdOwnerNo"),
                                UnitFlag = dsData[i].DataMain.Rows[0].DataRowGetByteValue("UnitFlag"),
                                UnitRule = dsData[i].DataMain.Rows[0].DataRowGetStringValue("UnitRule"),
                                WmsRemark = dsData[i].DataMain.Rows[0].DataRowGetStringValue("WmsRemark"),
                                CustomerNo = dsData[i].DataMain.Rows[0].DataRowGetStringValue("CustomerNo"),
                                ExpressCode = dsData[i].DataMain.Rows[0].DataRowGetStringValue("ExpressCode"),
                                LogisticsName = dsData[i].DataMain.Rows[0].DataRowGetStringValue("LogisticsName"),
                                OperateTime = dsData[i].DataMain.Rows[0].DataRowGetStringValue("OperateTime"),
                                OperatorCode = dsData[i].DataMain.Rows[0].DataRowGetStringValue("OperatorCode"),
                                OperatorName = dsData[i].DataMain.Rows[0].DataRowGetStringValue("OperatorName"),
                                OrderAmount = dsData[i].DataMain.Rows[0].DataRowGetStringValue("OrderAmount"),
                                AllowLack = dsData[i].DataMain.Rows[0].DataRowGetBoolValue("AllowLack"),
                                IsPorterTeam= dsData[i].DataMain.Rows[0].DataRowGetByteValue("IsPorterTeam")
                            },
                            OrderLines = OrderLines
                        }
                    };
                    var jsonrequest = JsonConvert.SerializeObject(request);
                    //{"response":{"content":{"code":"1","createTime":"2020-04-03 13:40:51","entryOrderCode":"CPL4418047893011","flag":"success","message":"成功"}, "code":0}}
                    var response = client.Execute(request);
                    await _jobLogger.WriteLogAsync(LogType.Info, "推送采购订单信息", $"入参：\r\n{jsonrequest},返回Json:\r\n{response.Body}");
                    //如果请求执行正确,从这里获取强类型返回值
                    OrderResponseBody returnValue = JsonConvert.DeserializeObject<OrderResponseBody>(response.Body);

                    if (returnValue.response == null)
                    {
                        await sqlHelper.ExecSqlAsync(dsData[i].AfterFailure);
                        await _jobLogger.WriteLogAsync(LogType.Info, "推送采购订单信息", $"失败后执行语句:{dsData[i].AfterFailure}");
                        return -1;
                    }
                    if (returnValue.response.code == 0)
                    {
                        if (returnValue.response.content.flag == "success")
                        {
                            var insertresult = await sqlHelper.ExecSqlAsync($"insert into STOCKORDERFORM_XH_JDWMS(BILLNO,SYNCDATE,ENTRYORDERCODE) values('{dsData[i].DataMain.Rows[0]["BILLNO"].SqlDataBankToString()}',{createdate},'{returnValue.response.content.entryOrderCode}')");
                            if (string.IsNullOrEmpty(insertresult))
                            {
                                await sqlHelper.ExecSqlAsync(dsData[i].AfterSuccess);
                                await _jobLogger.WriteLogAsync(LogType.Info, "推送采购订单信息", $"{dsData[i].DataMain.Rows[0]["BILLNO"].SqlDataBankToString()}成功,成功后执行语句:{dsData[i].AfterSuccess}");
                            }
                            else
                            {
                                await sqlHelper.ExecSqlAsync($"insert into ERRORDATA_XH_JDWMS(GUID,ERRORNO,ERRORTYPE,MAINFIELD,ERRORDATE,ERRORMSG) values('{Guid.NewGuid():N}',{dsData[i].DataMain.Rows[0]["BILLNO"].SqlDataBankToString()},'cgdd','BILLNO',{createdate},'{returnValue.response.content.message}')");
                                await _jobLogger.WriteLogAsync(LogType.Info, "推送采购订单信息", $"{dsData[i].DataMain.Rows[0]["BILLNO"].SqlDataBankToString()}失败,原因:{returnValue.response.content.message + insertresult}");
                            }
                        }
                        else
                        {
                            await sqlHelper.ExecSqlAsync($"insert into ERRORDATA_XH_JDWMS(GUID,ERRORNO,ERRORTYPE,MAINFIELD,ERRORDATE,ERRORMSG) values('{Guid.NewGuid():N}',{dsData[i].DataMain.Rows[0]["BILLNO"].SqlDataBankToString()},'cgdd','BILLNO',{createdate},'{returnValue.response.content.message}')");
                            await sqlHelper.ExecSqlAsync(dsData[i].AfterFailure);
                            await _jobLogger.WriteLogAsync(LogType.Info, "推送采购订单信息", $"{dsData[i].DataMain.Rows[0]["BILLNO"].SqlDataBankToString()}失败,原因:{returnValue.response.content.message},失败后执行语句:{dsData[i].AfterFailure}");
                        }

                    }
                    //响应的原始报文,如果请求失败,从这里获取错误消息代码
                    else
                    {
                        await sqlHelper.ExecSqlAsync(dsData[i].AfterFailure);
                        await _jobLogger.WriteLogAsync(LogType.Info, "推送采购订单信息", $"失败，返回:{JsonConvert.SerializeObject(response)}");
                    }
                }
                catch (Exception ex)
                {

                    await _jobLogger.WriteLogAsync(LogType.Info, "推送采购订单信息", $"失败，返回:{ex.Message},失败后执行语句:{dsData[i].AfterFailure}");
                    return -1;
                }
                finally
                {
                    sqlHelper.Dispose();
                }

            }
            return 0;
        }

        /// <summary>
        /// 推送店铺信息
        /// </summary>
        /// <param name="jobPara"></param>
        /// <param name="dsData"></param>
        /// <returns></returns>
        public async Task<int> ShopInfo(JobPara jobPara, List<Datas> dsData)
        {
            try
            {


                if (string.IsNullOrEmpty(serverUrl) || string.IsNullOrEmpty(accessToken) || string.IsNullOrEmpty(appKey) || string.IsNullOrEmpty(appSecret) || string.IsNullOrEmpty(Pin))
                {
                    await _jobLogger.WriteLogAsync(LogType.Info, "推送店铺信息", $"失败:数据源中缺少serverUrl、accessToken、appKey、appSecret、Pin!");
                    return -1;

                }
                else
                {
                    client = new DefaultJdClient(serverUrl, accessToken, appKey, appSecret);
                }
                for (int i = 0; i < dsData.Count; i++)
                {
                    var request = new ClpsSynchronizeShopLopRequest
                    {

                        Pin = Pin,
                        ShopIn = new SynchroShopModel
                        {
                            ActionType = "add",
                            Status = "1",
                            IsvShopNo = dsData[i].DataMain.Rows[0]["CODE"].SqlDataBankToString(),
                            SpSourceNo = "1",
                            OwnerNo = dsData[i].DataMain.Rows[0]["ownerCode"].SqlDataBankToString(),
                            Type = dsData[i].DataMain.Rows[0].DataRowGetStringValue("Type"),
                            ShopNo = dsData[i].DataMain.Rows[0].DataRowGetStringValue("ShopNo"),
                            SpShopNo = dsData[i].DataMain.Rows[0].DataRowGetStringValue("SpShopNo"),
                            ShopName = dsData[i].DataMain.Rows[0]["NAME"].SqlDataBankToString(),
                            Contacts = dsData[i].DataMain.Rows[0].DataRowGetStringValue("Contacts"),
                            Phone = dsData[i].DataMain.Rows[0].DataRowGetStringValue("Phone"),
                            Address = dsData[i].DataMain.Rows[0].DataRowGetStringValue("Address"),
                            Email = dsData[i].DataMain.Rows[0].DataRowGetStringValue("Email"),
                            Fax = dsData[i].DataMain.Rows[0].DataRowGetStringValue("Fax"),
                            AfterSaleAddress = dsData[i].DataMain.Rows[0]["ADDR"].SqlDataBankToString(),
                            AfterSaleContacts = "售后联系人",
                            AfterSalePhone = dsData[i].DataMain.Rows[0]["TEL"].SqlDataBankToString(),
                            BdOwnerNo = dsData[i].DataMain.Rows[0].DataRowGetStringValue("BdOwnerNo"),
                            OutstoreRules = dsData[i].DataMain.Rows[0].DataRowGetStringValue("OutstoreRules"),
                            BizType = dsData[i].DataMain.Rows[0].DataRowGetStringValue("BizType")
                        }
                    };
                    var jsonrequest = JsonConvert.SerializeObject(request);
                    //{"response":{"content":{"code":"1","flag":"success","isvShopNo":"0001","message":"成功","shopNo":"CSP0020000045959"}, "code":0}}
                    var response = client.Execute(request);
                    // CommonHelper.Log($"入参:\r\n{JsonConvert.SerializeObject(request)}\r\n 返回数据:\r\n:{JsonConvert.SerializeObject(response)}", "推送供应商信息");
                    await _jobLogger.WriteLogAsync(LogType.Info, "推送店铺信息", $"入参：\r\n{jsonrequest},返回Json:\r\n{response.Body}");
                    //如果请求执行正确,从这里获取强类型返回值
                    ShopResponseBody returnValue = JsonConvert.DeserializeObject<ShopResponseBody>(response.Body);


                    if (returnValue.response == null)
                    {
                        await sqlHelper.ExecSqlAsync(dsData[i].AfterFailure);
                        await _jobLogger.WriteLogAsync(LogType.Info, "推送店铺信息", $"失败后执行语句:{dsData[i].AfterFailure}");
                        return -1;
                    }

                    if (returnValue.response.code == 0)
                    {
                        if (returnValue.response.content.flag == "success")
                        {
                            //将返回的ClpsSupplierNo保存一下
                            var insertresult = await sqlHelper.ExecSqlAsync($"insert into ORGANIZATION_XH_JDWMS(SHOPNO,CODE,SYNCDATE) values('{returnValue.response.content.shopNo}','{dsData[i].DataMain.Rows[0]["CODE"].SqlDataBankToString()}',{createdate})");
                            if (string.IsNullOrEmpty(insertresult))
                            {
                                await sqlHelper.ExecSqlAsync(dsData[i].AfterSuccess);
                                await _jobLogger.WriteLogAsync(LogType.Info, "推送店铺信息", $"{dsData[i].DataMain.Rows[0]["CODE"].SqlDataBankToString()}成功,成功后执行语句:{dsData[i].AfterSuccess}");
                            }
                            else
                            {
                                await sqlHelper.ExecSqlAsync($"insert into ERRORDATA_XH_JDWMS(GUID,ERRORNO,ERRORTYPE,MAINFIELD,ERRORDATE,ERRORMSG) values('{Guid.NewGuid():N}',{dsData[i].DataMain.Rows[0]["CODE"].SqlDataBankToString()},'dp','CODE',{createdate},'{returnValue.response.content.message}')");
                                await _jobLogger.WriteLogAsync(LogType.Info, "推送店铺信息", $"{dsData[i].DataMain.Rows[0]["CODE"].SqlDataBankToString()}失败,原因:{returnValue.response.content.message + insertresult}");
                            }
                        }
                        else
                        {
                            await sqlHelper.ExecSqlAsync($"insert into ERRORDATA_XH_JDWMS(GUID,ERRORNO,ERRORTYPE,MAINFIELD,ERRORDATE,ERRORMSG) values('{Guid.NewGuid():N}',{dsData[i].DataMain.Rows[0]["CODE"].SqlDataBankToString()},'dp','CODE',{createdate},'{returnValue.response.content.message}')");
                            await sqlHelper.ExecSqlAsync(dsData[i].AfterFailure);
                            await _jobLogger.WriteLogAsync(LogType.Info, "推送店铺信息", $"{dsData[i].DataMain.Rows[0]["CODE"].SqlDataBankToString()}失败,原因:{returnValue.response.content.message},失败后执行语句:{dsData[i].AfterFailure}");
                        }
                    }
                    //响应的原始报文,如果请求失败,从这里获取错误消息代码
                    else
                    {
                        await sqlHelper.ExecSqlAsync(dsData[i].AfterFailure);
                        await _jobLogger.WriteLogAsync(LogType.Info, "推送店铺信息", $"失败返回:{JsonConvert.SerializeObject(response)},失败后执行语句:{dsData[i].AfterFailure}");
                    }

                }
                return 0;
            }
            catch (Exception ex)
            {
                await _jobLogger.WriteLogAsync(LogType.Info, "推送店铺信息", $"失败，{ex.Message}");
                return -1;
            }
            finally
            {
                sqlHelper.Dispose();
            }
        }

        /// <summary>
        /// 订单关闭
        /// </summary>
        /// <param name="jobPara"></param>
        /// <param name="dsData"></param>
        /// <returns></returns>
        public async Task<int> OrderClose(JobPara jobPara, List<Datas> dsData)
        {
            try
            {
                if (string.IsNullOrEmpty(serverUrl) || string.IsNullOrEmpty(accessToken) || string.IsNullOrEmpty(appKey) || string.IsNullOrEmpty(appSecret) || string.IsNullOrEmpty(Pin))
                {
                    await _jobLogger.WriteLogAsync(LogType.Info, "异常订单关闭", $"失败:数据源中缺少serverUrl、accessToken、appKey、appSecret、Pin!");
                    return -1;

                }
                else
                {
                    client = new DefaultJdClient(serverUrl, accessToken, appKey, appSecret);
                }
                for (int i = 0; i < dsData.Count; i++)
                {
                    var request = new ClpsClpsOrderCancelLopRequest
                    {
                        Pin = Pin,
                        OrderCancelRequest = new OrderCancelRequest
                        {
                            WarehouseCode = dsData[i].DataMain.Rows[0].DataRowGetStringValue("warehouseNo"),
                            OwnerCode = dsData[i].DataMain.Rows[0].DataRowGetStringValue("ownerCode"),
                            OrderId = dsData[i].DataMain.Rows[0].DataRowGetStringValue("ORDERID"),
                            OrderType = dsData[i].DataMain.Rows[0].DataRowGetStringValue("ORDERTYPE"),
                            CancelReason = dsData[i].DataMain.Rows[0].DataRowGetStringValue("CancelReason"),
                            OrderCode = dsData[i].DataMain.Rows[0].DataRowGetStringValue("OrderCode"),
                            TargetDeptCode = dsData[i].DataMain.Rows[0].DataRowGetStringValue("TargetDeptCode")
                        }
                    };
                    var jsonrequest = JsonConvert.SerializeObject(request);
                    //{"response":{"content":{"code":"1","createTime":"2020-04-09 14:11:02","entryOrderCode":"CPL4418047912171","flag":"success","message":"成功"}, "code":0}}
                    var response = client.Execute(request);
                    await _jobLogger.WriteLogAsync(LogType.Info, "异常订单关闭", $"入参：\r\n{jsonrequest},返回Json:\r\n{response.Body}");
                    //如果请求执行正确,从这里获取强类型返回值
                    OrderResponseBody returnValue = JsonConvert.DeserializeObject<OrderResponseBody>(response.Body);
                    if (returnValue.response == null)
                    {
                        await sqlHelper.ExecSqlAsync(dsData[i].AfterFailure);
                        await _jobLogger.WriteLogAsync(LogType.Info, "异常订单关闭", $"失败后执行语句:{dsData[i].AfterFailure}");
                        return -1;
                    }


                    if (returnValue.response.code == 0)
                    {
                        if (returnValue.response.content.flag == "success")
                        {
                            var insertresult = await sqlHelper.ExecSqlAsync($"insert into CloseOrder_XH_JDWMS(BILLNO,SYNCDATE,CLPSCODE,TYPE) values('{dsData[i].DataMain.Rows[0]["BILLNO"].SqlDataBankToString()}',{createdate},'{ dsData[i].DataMain.Rows[0]["ORDERID"].SqlDataBankToString()}','{dsData[i].DataMain.Rows[0]["ORDERTYPE"].SqlDataBankToString()}')");
                            if (string.IsNullOrEmpty(insertresult))
                            {
                                await sqlHelper.ExecSqlAsync(dsData[i].AfterSuccess);
                                await _jobLogger.WriteLogAsync(LogType.Info, "异常订单关闭", $"{dsData[i].DataMain.Rows[0]["BILLNO"].SqlDataBankToString()}成功!成功后执行语句:{dsData[i].AfterSuccess}");
                            }
                            else
                            {
                                await sqlHelper.ExecSqlAsync($"insert into ERRORDATA_XH_JDWMS(GUID,ERRORNO,ERRORTYPE,MAINFIELD,ERRORDATE,ERRORMSG) values('{Guid.NewGuid():N}',{dsData[i].DataMain.Rows[0]["BILLNO"].SqlDataBankToString()},'djqx','BILLNO',{createdate},'{returnValue.response.content.message}')");
                                await _jobLogger.WriteLogAsync(LogType.Info, "异常订单关闭", $"失败,原因:{returnValue.response.content.message + insertresult}");
                            }
                        }
                        else
                        {
                            await sqlHelper.ExecSqlAsync($"insert into ERRORDATA_XH_JDWMS(GUID,ERRORNO,ERRORTYPE,MAINFIELD,ERRORDATE,ERRORMSG) values('{Guid.NewGuid():N}',{dsData[i].DataMain.Rows[0]["BILLNO"].SqlDataBankToString()},'djqx','BILLNO',{createdate},'{returnValue.response.content.message}')");
                            await sqlHelper.ExecSqlAsync(dsData[i].AfterFailure);
                            await _jobLogger.WriteLogAsync(LogType.Info, "异常订单关闭", $"失败,原因:{returnValue.response.content.message},失败后执行语句:{dsData[i].AfterFailure}");
                        }

                    }
                    //响应的原始报文,如果请求失败,从这里获取错误消息代码
                    else
                    {
                        await sqlHelper.ExecSqlAsync(dsData[i].AfterFailure);
                        await _jobLogger.WriteLogAsync(LogType.Info, "异常订单关闭", $"失败,返回:{JsonConvert.SerializeObject(response)},失败后执行语句:{dsData[i].AfterFailure}");
                    }

                }
                return 0;
            }
            catch (Exception ex)
            {
                await _jobLogger.WriteLogAsync(LogType.Info, "异常订单关闭", $"失败,返回:{ex.Message}");
                return -1;
            }
            finally
            {
                sqlHelper.Dispose();
            }
        }

        /// <summary>
        /// 推送商品信息到笛佛
        /// </summary>
        /// <param name="jobPara"></param>
        /// <param name="dsData"></param>
        /// <returns></returns>
        public async Task<int> WdgjGoods(JobPara jobPara, List<Datas> dsData)
        {
            try
            {
                if (string.IsNullOrEmpty(wdgj_appkey) || string.IsNullOrEmpty(wdgj_appsecret) || string.IsNullOrEmpty(wdgj_accesstoken))
                {
                    await _jobLogger.WriteLogAsync(LogType.Info, "推送商品信息到笛佛", $"失败:数据源中缺少wdgj_appkey、wdgj_appsecret、wdgj_accesstoken!");
                    return -1;

                }
                OpenApi wdgjOpenApi = new OpenApi
                {
                    Appkey = wdgj_appkey,
                    AppSecret = wdgj_appsecret,
                    AccessToken = wdgj_accesstoken,
                    Timestamp = ((DateTime.Now.ToUniversalTime().Ticks - 621355968000000000) / 10000000).ToString(),
                    Method = "wdgj.goods.create",
                    Format = "json",
                    Versions = "1.0",
                };


                ArrayList arrayList = new ArrayList();
                List<GoodsDatainfo> datainfo = new List<GoodsDatainfo>();
                for (int i = 0; i < dsData.Count; i++)
                {
                    datainfo.Add(new GoodsDatainfo
                    {
                        goodsno = dsData[i].DataMain.Rows[0].DataRowGetStringValue("HH"),
                        goodsname = dsData[i].DataMain.Rows[0].DataRowGetStringValue("PM"),
                        unit = dsData[i].DataMain.Rows[0].DataRowGetStringValue("PDW"),
                        bgift = dsData[i].DataMain.Rows[0].DataRowGetIntValue("ISGIFT"),
                        bmultispec = "0",
                        bnegativestock = dsData[i].DataMain.Rows[0].DataRowGetStringValue("bnegativestock") =="" ? "0" : dsData[i].DataMain.Rows[0].DataRowGetStringValue("bnegativestock"),
                        barcode = dsData[i].DataMain.Rows[0].DataRowGetStringValue("TM"),
                        speclist = new List<specinfo>
                            {
                                new specinfo
                                {
                                    bblockup = dsData[i].DataMain.Rows[0].DataRowGetStringValue("bblockup") == "" ?"0" :dsData[i].DataMain.Rows[0].DataRowGetStringValue("bblockup"),
                                    bfixcost = dsData[i].DataMain.Rows[0].DataRowGetStringValue("bfixcost") == "" ?"0" :dsData[i].DataMain.Rows[0].DataRowGetStringValue("bfixcost"),
                                    speccode = dsData[i].DataMain.Rows[0].DataRowGetStringValue("speccode"),
                                    specname =dsData[i].DataMain.Rows[0].DataRowGetStringValue("specname"),
                                    expdate = dsData[i].DataMain.Rows[0].DataRowGetStringValue("expdate"),
                                    fixcostprice = dsData[i].DataMain.Rows[0].DataRowGetStringValue("fixcostprice"),
                                    specid = dsData[i].DataMain.Rows[0].DataRowGetStringValue("specid"),
                                    remark = dsData[i].DataMain.Rows[0].DataRowGetStringValue("remark"),
                                    weight = dsData[i].DataMain.Rows[0].DataRowGetStringValue("weight") 
                                }
                            }
                    });
                    arrayList.Add(dsData[i].DataMain.Rows[0].DataRowGetStringValue("HH"));
                }

                WdgjGoodsModel wdgjGoodsModel = new WdgjGoodsModel
                {
                    datalist = datainfo
                };

                string createGoodsJson = JsonConvert.SerializeObject(wdgjGoodsModel, new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore });
                wdgjOpenApi.AppParam.content = createGoodsJson;
                string postresult = wdgjOpenApi.HttpPostString();
                WdgjGoodsResponse wdgjGoodsResponse = JsonConvert.DeserializeObject<WdgjGoodsResponse>(postresult);
                await _jobLogger.WriteLogAsync(LogType.Info, "推送商品信息到笛佛", $"入参：\r\n{createGoodsJson},返回Json:\r\n{postresult}");
                if (wdgjGoodsResponse.datalist?.Count > 0)
                {
                    string falsehhs = "";
                    for (int i = 0; i < wdgjGoodsResponse.datalist.Count; i++)
                    {
                        if (falsehhs == "")
                        {
                            falsehhs = $"'{wdgjGoodsResponse.datalist[i].goodsno}'";
                        }
                        else
                        {
                            falsehhs += $",'{wdgjGoodsResponse.datalist[i].goodsno}'";
                        }
                        arrayList.Remove(wdgjGoodsResponse.datalist[i].goodsno);
                    }
                    string falseupdate = $"update yw_kck_xh_jdwms set ISWDGJ = '2' where hh in ({falsehhs})";
                    var updateresult = await sqlHelper.ExecSqlAsync(falseupdate);
                    await _jobLogger.WriteLogAsync(LogType.Info, "推送商品信息到笛佛", $"更新sql语句:{falseupdate}\r\n,返回信息:{updateresult}");
                }

                if (wdgjGoodsResponse.returncode == "0")
                {
                    string successhhs = "";
                    for (int i = 0; i < arrayList.Count; i++)
                    {
                        if (successhhs == "")
                        {
                            successhhs = $"'{arrayList[i]}'";
                        }
                        else
                        {
                            successhhs += $",'{arrayList[i]}'";
                        }
                    }
                    string successupdate = $"update yw_kck_xh_jdwms set ISWDGJ = '1' where hh in ({successhhs})";
                    var updateresult = await sqlHelper.ExecSqlAsync(successupdate);
                    await _jobLogger.WriteLogAsync(LogType.Info, "推送商品信息到笛佛", $"更新sql语句:{successupdate},返回信息:{updateresult}");
                }
                return 0;
            }
            catch (Exception ex)
            {
                await _jobLogger.WriteLogAsync(LogType.Info, "推送商品信息到笛佛", $"失败:{ ex.Message}");
                return -1;
            }
            finally
            {
                sqlHelper.Dispose();
            }
        }

        /// <summary>
        /// 笛佛供应商信息
        /// </summary>
        /// <param name="jobPara"></param>
        /// <param name="dsData"></param>
        /// <returns></returns>
        public async Task<int> WdgjSupplier(JobPara jobPara, List<Datas> dsData)
        {
            try
            {
                if (string.IsNullOrEmpty(wdgj_appkey) || string.IsNullOrEmpty(wdgj_appsecret) || string.IsNullOrEmpty(wdgj_accesstoken))
                {
                    await _jobLogger.WriteLogAsync(LogType.Info, "推送供应商信息到笛佛", $"失败:数据源中缺少wdgj_appkey、wdgj_appsecret、wdgj_accesstoken!");
                    return -1;

                }
                OpenApi wdgjOpenApi = new OpenApi
                {
                    Appkey = wdgj_appkey,
                    AppSecret = wdgj_appsecret,
                    AccessToken = wdgj_accesstoken,
                    Timestamp = ((DateTime.Now.ToUniversalTime().Ticks - 621355968000000000) / 10000000).ToString(),
                    Method = "wdgj.prover.create",
                    Format = "json",
                    Versions = "1.0"

                };
                ArrayList arrayList = new ArrayList();
                List<SupplierDatainfo> supplierDatainfos = new List<SupplierDatainfo>();
                for (int i = 0; i < dsData.Count; i++)
                {
                    supplierDatainfos.Add(new SupplierDatainfo
                    {
                        providername = dsData[i].DataMain.Rows[0].DataRowGetStringValue("MC"),
                        providerno = dsData[i].DataMain.Rows[0].DataRowGetStringValue("TJBH"),
                        provideralias = dsData[i].DataMain.Rows[0].DataRowGetStringValue("MC")
                    });

                    arrayList.Add(dsData[i].DataMain.Rows[0].DataRowGetStringValue("TJBH"));
                }

                WdgjSupplierModel wdgjSupplier = new WdgjSupplierModel
                {
                    datalist = supplierDatainfos
                };
                string createSuppliersJson = JsonConvert.SerializeObject(wdgjSupplier, new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore });
                wdgjOpenApi.AppParam.content = createSuppliersJson;

                string postresult = wdgjOpenApi.HttpPostString();
                WdgjSupplierResponse supplierResponse = JsonConvert.DeserializeObject<WdgjSupplierResponse>(postresult);
                await _jobLogger.WriteLogAsync(LogType.Info, "推送供应商信息到笛佛", $"入参：\r\n{createSuppliersJson},返回Json:\r\n{postresult}");
                if (supplierResponse.datalist?.Count > 0)
                {
                    string falsehhs = "";
                    for (int i = 0; i < supplierResponse.datalist.Count; i++)
                    {
                        if (falsehhs == "")
                        {
                            falsehhs = $"'{supplierResponse.datalist[i].providerno}'";
                        }
                        else
                        {
                            falsehhs += $",'{supplierResponse.datalist[i].providerno}'";
                        }
                        // remove the error hh
                        arrayList.Remove(supplierResponse.datalist[i].providerno);
                    }

                    string falseupdate = $"update GL_SUPER_XH_JDWMS set ISWDGJ = '2' where TJBH in({falsehhs})";
                    var updateresult = await sqlHelper.ExecSqlAsync(falseupdate);
                    await _jobLogger.WriteLogAsync(LogType.Info, "推送供应商信息到笛佛", $"更新sql语句:{falseupdate}\r\n,返回信息:{updateresult}");
                }

                if (supplierResponse.returncode == "0")
                {
                    string successhhs = "";
                    for (int i = 0; i < arrayList.Count; i++)
                    {
                        if (successhhs == "")
                        {
                            successhhs = $"'{arrayList[i]}'";
                        }
                        else
                        {
                            successhhs += $",'{arrayList[i]}'";
                        }
                    }
                    string successupdate = $"update GL_SUPER_XH_JDWMS set ISWDGJ = '1' where TJBH in({successhhs})";
                    var updateresult = await sqlHelper.ExecSqlAsync(successupdate);
                    await _jobLogger.WriteLogAsync(LogType.Info, "推送供应商信息到笛佛", $"更新sql语句:{successupdate},返回信息:{updateresult}");
                }
                return 0;
            }
            catch (Exception ex)
            {
                await _jobLogger.WriteLogAsync(LogType.Info, "推送供应商信息到笛佛", $"失败:{ex.Message}");
                return -1;
            }
            finally
            {
                sqlHelper.Dispose();
            }
        }

        /// <summary>
        /// 推送供应商信息
        /// </summary>
        /// <param name="jobPara"></param>
        /// <param name="dsData"></param>
        /// <returns></returns>
        public async Task<int> SupplierInfo(JobPara jobPara, List<Datas> dsData)
        {
            try
            {
                if (string.IsNullOrEmpty(serverUrl) || string.IsNullOrEmpty(accessToken) || string.IsNullOrEmpty(appKey) || string.IsNullOrEmpty(appSecret) || string.IsNullOrEmpty(Pin))
                {
                    await _jobLogger.WriteLogAsync(LogType.Info, "推送供应商信息", $"失败:数据源中缺少serverUrl、accessToken、appKey、appSecret、Pin!");
                    return -1;

                }
                else
                {
                    client = new DefaultJdClient(serverUrl, accessToken, appKey, appSecret);
                }


                for (int i = 0; i < dsData.Count; i++)
                {
                    var request = new ClpsSynchronizeSupplierLopRequest
                    {
                        Pin = Pin,
                        SupplierModel = new SynchroSupplierModel
                        {
                            ActionType = "add",
                            Status = "2",
                            SupplierName = dsData[i].DataMain.Rows[0].DataRowGetStringValue("MC"),
                            SupplierType = dsData[i].DataMain.Rows[0].DataRowGetStringValue("SupplierType"),
                            ClpsSupplierNo = "",
                            IsvSupplierNo = dsData[i].DataMain.Rows[0].DataRowGetStringValue("TJBH"),
                            Address = dsData[i].DataMain.Rows[0].DataRowGetStringValue("ADDR"),
                            City = dsData[i].DataMain.Rows[0].DataRowGetStringValue("City"),
                            Contacts = dsData[i].DataMain.Rows[0].DataRowGetStringValue("LXR"),
                            County = dsData[i].DataMain.Rows[0].DataRowGetStringValue("County"),
                            Email = dsData[i].DataMain.Rows[0].DataRowGetStringValue("EMAIL"),
                            Ext1 = dsData[i].DataMain.Rows[0].DataRowGetStringValue("Ext1"),
                            Ext2 = dsData[i].DataMain.Rows[0].DataRowGetStringValue("Ext2"),
                            Ext3 = dsData[i].DataMain.Rows[0].DataRowGetStringValue("Ext3"),
                            Ext4 = dsData[i].DataMain.Rows[0].DataRowGetStringValue("Ext4"),
                            Ext5 = dsData[i].DataMain.Rows[0].DataRowGetStringValue("Ext5"),
                            Fax = dsData[i].DataMain.Rows[0].DataRowGetStringValue("Fax"),
                            Mobile = dsData[i].DataMain.Rows[0].DataRowGetStringValue("TEL"),
                            OwnerName = dsData[i].DataMain.Rows[0].DataRowGetStringValue("OwnerName"),
                            OwnerNo = dsData[i].DataMain.Rows[0].DataRowGetStringValue("ownerCode"),
                            Phone = dsData[i].DataMain.Rows[0].DataRowGetStringValue("TEL"),
                            Province = dsData[i].DataMain.Rows[0].DataRowGetStringValue("Province"),
                            Town = dsData[i].DataMain.Rows[0].DataRowGetStringValue("Town")
                        }
                    };
                    var jsonrequest = JsonConvert.SerializeObject(request);
                    //{"response":{"content":{"clpsSupplierNo":"CMS4418046522447","code":"1","flag":"success","isvSupplierNo":"00002","message":"成功"}, "code":0}}
                    var response = client.Execute(request);
                    // CommonHelper.Log($"入参:\r\n{JsonConvert.SerializeObject(request)}\r\n 返回数据:\r\n:{JsonConvert.SerializeObject(response)}", "推送供应商信息");
                    await _jobLogger.WriteLogAsync(LogType.Info, "推送供应商信息", $"入参：\r\n{jsonrequest},返回Json:\r\n{response.Body}");
                    //如果请求执行正确,从这里获取强类型返回值
                    SupplierResponseBody returnValue = JsonConvert.DeserializeObject<SupplierResponseBody>(response.Body);

                    if (returnValue.response == null)
                    {
                        await sqlHelper.ExecSqlAsync(dsData[i].AfterFailure);
                        await _jobLogger.WriteLogAsync(LogType.Info, "推送供应商信息", $"失败返回:{response.Body},失败后执行语句:{dsData[i].AfterFailure}");
                    }
                    if (returnValue.response.code == 0)
                    {
                        if (returnValue.response.content.flag == "success")
                        {
                            //将返回的ClpsSupplierNo保存一下
                            var insertresult = await sqlHelper.ExecSqlAsync($"insert into GL_SUPER_XH_JDWMS(CLPSSUPPLIERNO,TJBH,SYNCDATE) values('{returnValue.response.content.clpsSupplierNo}','{dsData[i].DataMain.Rows[0]["TJBH"].SqlDataBankToString()}',{createdate})");
                            if (string.IsNullOrEmpty(insertresult))
                            {
                                await sqlHelper.ExecSqlAsync(dsData[i].AfterSuccess);
                                await _jobLogger.WriteLogAsync(LogType.Info, "推送供应商信息", $"供应商信息{dsData[i].DataMain.Rows[0]["TJBH"].SqlDataBankToString()}成功!成功后执行语句:{dsData[i].AfterSuccess}");
                            }
                            else
                            {
                                await sqlHelper.ExecSqlAsync($"insert into ERRORDATA_XH_JDWMS(GUID,ERRORNO,ERRORTYPE,MAINFIELD,ERRORDATE,ERRORMSG) values('{Guid.NewGuid():N}',{dsData[i].DataMain.Rows[0]["TJBH"].SqlDataBankToString()},'gys','TJBH',{createdate},'{returnValue.response.content.message}')");
                                await _jobLogger.WriteLogAsync(LogType.Info, "推送供应商信息", $"{dsData[i].DataMain.Rows[0]["TJBH"].SqlDataBankToString()}失败,原因:{returnValue.response.content.message + insertresult}");
                            }
                        }
                        else
                        {
                            await sqlHelper.ExecSqlAsync($"insert into ERRORDATA_XH_JDWMS(GUID,ERRORNO,ERRORTYPE,MAINFIELD,ERRORDATE,ERRORMSG) values('{Guid.NewGuid():N}',{dsData[i].DataMain.Rows[0]["TJBH"].SqlDataBankToString()},'gys','TJBH',{createdate},'{returnValue.response.content.message}')");
                            await sqlHelper.ExecSqlAsync(dsData[i].AfterFailure);
                            await _jobLogger.WriteLogAsync(LogType.Info, "推送供应商信息", $"{dsData[i].DataMain.Rows[0]["TJBH"].SqlDataBankToString()}失败,原因:{returnValue.response.content.message},失败后执行语句:{dsData[i].AfterFailure}");
                        }
                    }
                    //响应的原始报文,如果请求失败,从这里获取错误消息代码
                    else
                    {
                        await sqlHelper.ExecSqlAsync(dsData[i].AfterFailure);
                        await _jobLogger.WriteLogAsync(LogType.Info, "推送供应商信息", $"失败:{JsonConvert.SerializeObject(response)},失败后执行语句:{dsData[i].AfterFailure}");
                    }

                }
                return 0;
            }
            catch (Exception ex)
            {
                await _jobLogger.WriteLogAsync(LogType.Info, "推送供应商信息", $"失败:{ex.Message}");
                return -1;
            }
            finally
            {
                sqlHelper.Dispose();
            }
        }

        /// <summary>
        /// 推送商品信息
        /// </summary>
        /// <param name="jobPara"></param>
        /// <param name="dsData"></param>
        /// <returns></returns>
        public async Task<int> DrugInfo(JobPara jobPara, List<Datas> dsData)
        {
           


                if (string.IsNullOrEmpty(serverUrl) || string.IsNullOrEmpty(accessToken) || string.IsNullOrEmpty(appKey) || string.IsNullOrEmpty(appSecret) || string.IsNullOrEmpty(Pin))
                {
                    await _jobLogger.WriteLogAsync(LogType.Info, "推送商品信息", $"失败:数据源中缺少serverUrl、accessToken、appKey、appSecret、Pin!");
                    return -1;

                }
                else
                {
                    client = new DefaultJdClient(serverUrl, accessToken, appKey, appSecret);
                }
                for (int i = 0; i < dsData.Count; i++)
                {
                try
                {
                    var OutPackUoms = new List<OutPackUom>();
                    OutPackUoms.Add(new OutPackUom
                    {
                        Height = "",
                        Length = "",
                        NetWeight = "",
                        OutUomName = "BigPack",
                        OutUomNo = "LARGEPACKUNIT",
                        OutUomQty = 1,
                        Volume = "",
                        Width = ""
                    });

                    var PackRules = new List<PackRule>();
                    PackRules.Add(new PackRule
                    {
                        OutPackUoms = OutPackUoms,
                        PackId = "BigPack",
                        PackName = "BigPack"
                    });

                    var request = new ClpsTransportSingleItemLopRequest
                    {
                        Pin = Pin,
                        SingleItemRequest = new SingleItemRequest
                        {
                            ActionType = dsData[i].DataMain.Rows[0].DataRowGetStringValue("actionType"),
                            WarehouseCode = dsData[i].DataMain.Rows[0].DataRowGetStringValue("warehouseNo"),
                            OwnerCode = dsData[i].DataMain.Rows[0].DataRowGetStringValue("ownerCode"),
                            Item = new Item
                            {
                                ItemCode = dsData[i].DataMain.Rows[0].DataRowGetStringValue("HH"),
                                ItemId = dsData[i].DataMain.Rows[0].DataRowGetStringValue("actionType") == "add" ? "" : dsData[i].DataMain.Rows[0].DataRowGetStringValue("ItemId"),
                                GoodsNumFloat = 0,
                                ShopNos = dsData[i].DataMain.Rows[0].DataRowGetStringValue("shopNos"),
                                SupplierCode = dsData[i].DataMain.Rows[0].DataRowGetStringValue("SupplierCode"),
                                SupplierName = dsData[i].DataMain.Rows[0].DataRowGetStringValue("SupplierName"),
                                GoodsCode = dsData[i].DataMain.Rows[0].DataRowGetStringValue("GoodsCode"),
                                ClpsGoodsCode = dsData[i].DataMain.Rows[0].DataRowGetStringValue("ClpsGoodsCode"),
                                ItemName = dsData[i].DataMain.Rows[0].DataRowGetStringValue("PM"),
                                ShortName = dsData[i].DataMain.Rows[0].DataRowGetStringValue("BM"),
                                EnglishName = dsData[i].DataMain.Rows[0].DataRowGetStringValue("EnglishName"),
                                BarCode = dsData[i].DataMain.Rows[0].DataRowGetStringValue("TM"),
                                SkuProperty = dsData[i].DataMain.Rows[0].DataRowGetStringValue("SkuProperty"),
                                StockUnitCode = dsData[i].DataMain.Rows[0].DataRowGetStringValue("PDW"),
                                StockUnitDesc = dsData[i].DataMain.Rows[0].DataRowGetStringValue("PDW"),
                                Length = dsData[i].DataMain.Rows[0].DataRowGetIntValue("Length"),
                                Width = dsData[i].DataMain.Rows[0].DataRowGetIntValue("Width"),
                                Height = dsData[i].DataMain.Rows[0].DataRowGetIntValue("Height"),
                                Volume = dsData[i].DataMain.Rows[0].DataRowGetIntValue("Volume"),
                                GrossWeight = dsData[i].DataMain.Rows[0].DataRowGetIntValue("GrossWeight"),
                                NetWeight = dsData[i].DataMain.Rows[0].DataRowGetIntValue("NetWeight"),
                                Color = dsData[i].DataMain.Rows[0].DataRowGetStringValue("Color"),
                                Size = dsData[i].DataMain.Rows[0].DataRowGetStringValue("Size"),
                                Title = dsData[i].DataMain.Rows[0].DataRowGetStringValue("Title"),
                                CategoryId = dsData[i].DataMain.Rows[0].DataRowGetStringValue("CategoryId"),
                                CategoryName = dsData[i].DataMain.Rows[0].DataRowGetStringValue("CategoryName"),
                                PricingCategory = dsData[i].DataMain.Rows[0].DataRowGetStringValue("PricingCategory"),
                                SafetyStock = dsData[i].DataMain.Rows[0].DataRowGetStringValue("SafetyStock"),
                                ItemType = dsData[i].DataMain.Rows[0].DataRowGetStringValue("ItemType") == "" ? "ZC" : dsData[i].DataMain.Rows[0].DataRowGetStringValue("ItemType"),
                                TagPrice = dsData[i].DataMain.Rows[0].DataRowGetIntValue("TagPrice"),
                                RetailPrice = dsData[i].DataMain.Rows[0].DataRowGetIntValue("RetailPrice"),
                                CostPrice = dsData[i].DataMain.Rows[0].DataRowGetIntValue("CostPrice"),
                                PurchasePrice = dsData[i].DataMain.Rows[0].DataRowGetIntValue("PurchasePrice"),
                                SeasonCode = dsData[i].DataMain.Rows[0].DataRowGetStringValue("SeasonCode"),
                                SeasonName = dsData[i].DataMain.Rows[0].DataRowGetStringValue("SeasonName"),
                                BrandCode = dsData[i].DataMain.Rows[0].DataRowGetStringValue("BrandCode"),
                                BrandName = dsData[i].DataMain.Rows[0].DataRowGetStringValue("BrandName"),
                                IsSNMgmt = dsData[i].DataMain.Rows[0].DataRowGetStringValue("IsSNMgmt") == "" ? "N" : dsData[i].DataMain.Rows[0].DataRowGetStringValue("IsSNMgmt"),
                                ProductDate = dsData[i].DataMain.Rows[0].DataRowGetStringValue("ProductDate"),
                                ExpireDate = dsData[i].DataMain.Rows[0].DataRowGetStringValue("ExpireDate"),
                                IsShelfLifeMgmt = dsData[i].DataMain.Rows[0].DataRowGetStringValue("IsShelfLifeMgmt"),
                                ShelfLife = dsData[i].DataMain.Rows[0].DataRowGetIntValue("ShelfLife"),
                                RejectLifecycle = dsData[i].DataMain.Rows[0].DataRowGetIntValue("RejectLifecycle"),
                                LockupLifecycle = dsData[i].DataMain.Rows[0].DataRowGetIntValue("LockupLifecycle"),
                                AdventLifecycle = dsData[i].DataMain.Rows[0].DataRowGetIntValue("AdventLifecycle"),
                                IsBatchMgmt = dsData[i].DataMain.Rows[0].DataRowGetStringValue("IsBatchMgmt") == "" ? "Y" : dsData[i].DataMain.Rows[0].DataRowGetStringValue("IsBatchMgmt"),
                                BatchCode = dsData[i].DataMain.Rows[0].DataRowGetStringValue("BatchCode"),
                                BatchRemark = dsData[i].DataMain.Rows[0].DataRowGetStringValue("BatchRemark"),
                                OriginAddress = dsData[i].DataMain.Rows[0].DataRowGetStringValue("OriginAddress"),
                                ApprovalNumber = dsData[i].DataMain.Rows[0].DataRowGetStringValue("ApprovalNumber"),
                                IsFragile = dsData[i].DataMain.Rows[0].DataRowGetStringValue("IsFragile"),
                                IsHazardous = dsData[i].DataMain.Rows[0].DataRowGetStringValue("IsHazardous"),
                                Remark = dsData[i].DataMain.Rows[0].DataRowGetStringValue("Remark"),
                                CreateTime = dsData[i].DataMain.Rows[0].DataRowGetStringValue("CreateTime"),
                                UpdateTime = dsData[i].DataMain.Rows[0].DataRowGetStringValue("UpdateTime"),
                                IsValid = dsData[i].DataMain.Rows[0].DataRowGetStringValue("IsValid") == "" ? "Y" : dsData[i].DataMain.Rows[0].DataRowGetStringValue("IsValid"),
                                IsSku = dsData[i].DataMain.Rows[0].DataRowGetStringValue("IsSku"),
                                PackageMaterial = dsData[i].DataMain.Rows[0].DataRowGetStringValue("PackageMaterial"),
                                SellerGoodsSign = dsData[i].DataMain.Rows[0].DataRowGetStringValue("SellerGoodsSign"),
                                SpGoodsNo = dsData[i].DataMain.Rows[0].DataRowGetStringValue("SpGoodsNo"),
                                InstoreThreshold = dsData[i].DataMain.Rows[0].DataRowGetIntValue("InstoreThreshold"),
                                OutstoreThreshold = dsData[i].DataMain.Rows[0].DataRowGetIntValue("OutstoreThreshold"),
                                Manufacturer = dsData[i].DataMain.Rows[0].DataRowGetStringValue("SCDW"),
                                SizeDefinition = dsData[i].DataMain.Rows[0].DataRowGetStringValue("SizeDefinition"),
                                CheapGift = dsData[i].DataMain.Rows[0].DataRowGetIntValue("ISGIFT") == 0 ? "N" : "Y",
                                Quality = dsData[i].DataMain.Rows[0].DataRowGetStringValue("Quality"),
                                Expensive = dsData[i].DataMain.Rows[0].DataRowGetStringValue("Expensive"),
                                Luxury = dsData[i].DataMain.Rows[0].DataRowGetStringValue("Luxury"),
                                Liquid = dsData[i].DataMain.Rows[0].DataRowGetStringValue("Liquid"),
                                Consumables = dsData[i].DataMain.Rows[0].DataRowGetStringValue("Consumables"),
                                Abnormal = dsData[i].DataMain.Rows[0].DataRowGetStringValue("Abnormal"),
                                Imported = dsData[i].DataMain.Rows[0].DataRowGetStringValue("Imported"),
                                Health = dsData[i].DataMain.Rows[0].DataRowGetStringValue("Health"),
                                Temperature = dsData[i].DataMain.Rows[0].DataRowGetStringValue("Temperature"),
                                TemperatureCeil = dsData[i].DataMain.Rows[0].DataRowGetStringValue("TemperatureCeil"),
                                TemperatureFloor = dsData[i].DataMain.Rows[0].DataRowGetStringValue("TemperatureFloor"),
                                Humidity = dsData[i].DataMain.Rows[0].DataRowGetStringValue("Humidity"),
                                HumidityCeil = dsData[i].DataMain.Rows[0].DataRowGetStringValue("HumidityCeil"),
                                HumidityFloor = dsData[i].DataMain.Rows[0].DataRowGetStringValue("HumidityFloor"),
                                Movable = dsData[i].DataMain.Rows[0].DataRowGetStringValue("Movable"),
                                Service3g = dsData[i].DataMain.Rows[0].DataRowGetStringValue("Service3g"),
                                Sample = dsData[i].DataMain.Rows[0].DataRowGetStringValue("Sample"),
                                Odor = dsData[i].DataMain.Rows[0].DataRowGetStringValue("Odor"),
                                Sex = dsData[i].DataMain.Rows[0].DataRowGetStringValue("Sex"),
                                Precious = dsData[i].DataMain.Rows[0].DataRowGetStringValue("Precious"),
                                MixedBatch = dsData[i].DataMain.Rows[0].DataRowGetStringValue("MixedBatch"),
                                FashionNo = dsData[i].DataMain.Rows[0].DataRowGetStringValue("FashionNo"),
                                CustomMade = dsData[i].DataMain.Rows[0].DataRowGetStringValue("CustomMade"),
                                AirMark = dsData[i].DataMain.Rows[0].DataRowGetStringValue("AirMark"),
                                LossRate = dsData[i].DataMain.Rows[0].DataRowGetStringValue("LossRate"),
                                SellPeriod = dsData[i].DataMain.Rows[0].DataRowGetStringValue("SellPeriod"),
                                IsPMX = dsData[i].DataMain.Rows[0].DataRowGetStringValue("IsPMX"),
                                QualityCheckRate = dsData[i].DataMain.Rows[0].DataRowGetStringValue("QualityCheckRate"),
                                ProductSeason = dsData[i].DataMain.Rows[0].DataRowGetStringValue("ProductSeason"),
                                MaterialNo = dsData[i].DataMain.Rows[0].DataRowGetStringValue("MaterialNo"),
                                PrIntegerProductId = dsData[i].DataMain.Rows[0].DataRowGetStringValue("PrIntegerProductId"),
                                PrIntegerName = dsData[i].DataMain.Rows[0].DataRowGetStringValue("PrIntegerName"),
                                BundleFlag = dsData[i].DataMain.Rows[0].DataRowGetStringValue("BundleFlag"),
                                ProductCategory = dsData[i].DataMain.Rows[0].DataRowGetIntValue("ISGIFT"),
                                Category = dsData[i].DataMain.Rows[0].DataRowGetStringValue("Category"),
                                Storage = dsData[i].DataMain.Rows[0].DataRowGetStringValue("CCTJ") == "" ? "常温" : dsData[i].DataMain.Rows[0].DataRowGetStringValue("CCTJ"),
                                Type = dsData[i].DataMain.Rows[0].DataRowGetStringValue("Type").ToUpper(),
                                Specification = dsData[i].DataMain.Rows[0].DataRowGetStringValue("GG"),
                                GenericName = dsData[i].DataMain.Rows[0].DataRowGetStringValue("GenericName"),
                                Dosage = dsData[i].DataMain.Rows[0].DataRowGetStringValue("Dosage"),
                                UseMethods = dsData[i].DataMain.Rows[0].DataRowGetStringValue("UseMethods"),
                                PackingUnit = dsData[i].DataMain.Rows[0].DataRowGetStringValue("PackingUnit"),
                                Efficacy = dsData[i].DataMain.Rows[0].DataRowGetStringValue("Efficacy"),
                                RegistrationNum = dsData[i].DataMain.Rows[0].DataRowGetStringValue("RegistrationNum"),
                                ApprovalNum = dsData[i].DataMain.Rows[0].DataRowGetStringValue("ApprovalNum"),
                                CuringType = dsData[i].DataMain.Rows[0].DataRowGetIntValue("CuringType"),
                                CuringPeriod = dsData[i].DataMain.Rows[0].DataRowGetIntValue("CuringPeriod"),
                                WarmLayer = dsData[i].DataMain.Rows[0].DataRowGetStringValue("WarmLayer"),
                                QualifyTypes = dsData[i].DataMain.Rows[0].DataRowGetIntValue("QualifyTypes"),
                                DosageForm = dsData[i].DataMain.Rows[0].DataRowGetStringValue("DosageForm"),
                                PackRules = PackRules,
                                Serial = 0,
                                TraceNoCollect = 0

                            }
                        }
                    };

                    var jsonrequest = JsonConvert.SerializeObject(request);
                    var response = client.Execute(request);
                    await _jobLogger.WriteLogAsync(LogType.Info, "推送商品信息", $"入参：\r\n{jsonrequest},返回Json:\r\n{response.Body}");
                    //{"response":{"content":{"clpsGoodsCode":"CMG4418274978871","code":"1","flag":"success","itemCode":"00000002","message":"商品同步成功"}, "code":0}}
                    //如果请求执行正确,从这里获取强类型返回值
                    SingelResponseBody returnValue = JsonConvert.DeserializeObject<SingelResponseBody>(response.Body);
                    if (returnValue.response == null)
                    {
                        await sqlHelper.ExecSqlAsync(dsData[i].AfterFailure);
                        await _jobLogger.WriteLogAsync(LogType.Info, "推送商品信息", $"失败后执行语句:{dsData[i].AfterFailure}");
                        return -1;
                    }

                    if (returnValue.response.code == 0)
                    {
                        if (returnValue.response.content.flag == "success")
                        {
                            
                            if (dsData[i].DataMain.Rows[0]["actionType"].SqlDataBankToString() == "add")
                            {
                                string insertsql = $"insert into YW_KCK_XH_JDWMS(CLPSGOODSCODE,HH,SYNCDATE) values('{returnValue.response.content.clpsGoodsCode}','{dsData[i].DataMain.Rows[0]["HH"].SqlDataBankToString()}',{createdate})";
                                var insertresult = await sqlHelper.ExecSqlAsync(insertsql);
                                if (string.IsNullOrEmpty(insertresult))
                                {
                                    await sqlHelper.ExecSqlAsync(dsData[i].AfterSuccess);
                                    await _jobLogger.WriteLogAsync(LogType.Info, "推送商品信息", $"{dsData[i].DataMain.Rows[0]["HH"].SqlDataBankToString()}成功!成功后执行语句:{dsData[i].AfterSuccess}");
                                }
                                else
                                {
                                    await sqlHelper.ExecSqlAsync(dsData[i].AfterFailure);
                                    await sqlHelper.ExecSqlAsync($"insert into ERRORDATA_XH_JDWMS(GUID,ERRORNO,ERRORTYPE,MAINFIELD,ERRORDATE,ERRORMSG) values('{Guid.NewGuid():N}',{dsData[i].DataMain.Rows[0]["HH"].SqlDataBankToString()},'sp','HH',{createdate},'{returnValue.response.content.message}')");

                                    await _jobLogger.WriteLogAsync(LogType.Info, "推送商品信息", $"{dsData[i].DataMain.Rows[0]["HH"].SqlDataBankToString()}失败,原因:{returnValue.response.content.message + insertresult},失败后执行语句:{dsData[i].AfterFailure}");
                                }
                            }
                            else
                            {
                                await sqlHelper.ExecSqlAsync(dsData[i].AfterSuccess);
                            }
                           
                        }
                        else
                        {
                            await sqlHelper.ExecSqlAsync($"insert into ERRORDATA_XH_JDWMS(GUID,ERRORNO,ERRORTYPE,MAINFIELD,ERRORDATE,ERRORMSG) values('{Guid.NewGuid():N}',{dsData[i].DataMain.Rows[0]["HH"].SqlDataBankToString()},'sp','HH',{createdate},'{returnValue.response.content.message}')");
                            await sqlHelper.ExecSqlAsync(dsData[i].AfterFailure);
                            await _jobLogger.WriteLogAsync(LogType.Info, "推送商品信息", $"{dsData[i].DataMain.Rows[0]["HH"].SqlDataBankToString()}失败,原因:{returnValue.response.content.message},失败后执行语句:{dsData[i].AfterFailure}");
                        }
                    }
                    //响应的原始报文,如果请求失败,从这里获取错误消息代码
                    else
                    {
                        await sqlHelper.ExecSqlAsync(dsData[i].AfterFailure);
                        await _jobLogger.WriteLogAsync(LogType.Info, "推送商品信息", $"失败返回:{JsonConvert.SerializeObject(response)},失败后执行语句:{dsData[i].AfterFailure}");
                    }
                }
                catch (Exception ex)
                {
                    await sqlHelper.ExecSqlAsync(dsData[i].AfterFailure);
                    await _jobLogger.WriteLogAsync(LogType.Info, "推送商品信息", $"失败:{ex.Message},失败后执行语句:{dsData[i].AfterFailure}");
                    return -1;
                }
                finally
                {
                    sqlHelper.Dispose();
                }
            }
                return 0;



           
        }

        /// <summary>
        /// 查询商品信息
        /// </summary>
        /// <param name="jobPara"></param>
        /// <param name="dsData"></param>
        /// <returns></returns>
        //public async Task<int> QueryDrug(JobPara jobPara, List<Datas> dsData)
        //{
        //    try
        //    {

        //        if (string.IsNullOrEmpty(serverUrl) || string.IsNullOrEmpty(accessToken) || string.IsNullOrEmpty(appKey) || string.IsNullOrEmpty(appSecret) || string.IsNullOrEmpty(Pin))
        //        {
        //            await _jobLogger.WriteLogAsync(LogType.Info, "查询商品信息", $"失败:数据源中缺少serverUrl、accessToken、appKey、appSecret、Pin!");
        //            return -1;

        //        }
        //        else
        //        {
        //            client = new DefaultJdClient(serverUrl, accessToken, appKey, appSecret);
        //        }
        //        for (int i = 0; i < dsData.Count; i++)
        //        {
        //            var request = new ClpsQueryItemLopRequest
        //            {
        //                Pin = Pin,
        //                ItemQueryRequest = new ItemQueryRequest
        //                {
        //                    Page = 1,
        //                    PageSize = 10,
        //                    ItemCode = dsData[i].DataMain.Rows[0]["HH"].SqlDataBankToString(),
        //                    OwnerCode = dsData[i].DataMain.Rows[0]["ownerCode"].SqlDataBankToString(),
        //                    QueryType = "2"
        //                }
        //            };
        //            var jsonrequest = JsonConvert.SerializeObject(request);
        //            var response = client.Execute(request);
        //            await _jobLogger.WriteLogAsync(LogType.Info, "查询商品信息", $"入参：\r\n{jsonrequest},返回Json:\r\n{response.Body}");
        //            //如果请求执行正确,从这里获取强类型返回值
        //            SelectGoods returnValue = JsonConvert.DeserializeObject<SelectGoods>(response.Body);
        //            if (response.Code == 0)
        //            {
        //                var insertresult = await sqlHelper.ExecSqlAsync($"update yw_kck_xh_jdwms set CLPSGOODSCODE ='{returnValue.response.content.items[0].itemId}' where HH ='{dsData[i].DataMain.Rows[0]["HH"].SqlDataBankToString()}'");
        //                if (string.IsNullOrEmpty(insertresult))
        //                {
        //                    await _jobLogger.WriteLogAsync(LogType.Info, "查询商品信息", $"{dsData[i].DataMain.Rows[0]["HH"].SqlDataBankToString()}成功");
        //                }
        //                else
        //                {
        //                    await _jobLogger.WriteLogAsync(LogType.Info, "查询商品信息", $"{dsData[i].DataMain.Rows[0]["HH"].SqlDataBankToString()}失败,原因:{insertresult}");
        //                }
        //            }
        //            //响应的原始报文,如果请求失败,从这里获取错误消息代码
        //            else
        //            {
        //                await _jobLogger.WriteLogAsync(LogType.Info, "查询商品信息", $"返回:{JsonConvert.SerializeObject(response)}");
        //            }

        //        }
        //        return 0;
        //    }
        //    catch (Exception ex)
        //    {
        //        await _jobLogger.WriteLogAsync(LogType.Info, "查询商品信息", $"失败，\r\n{ex.Message}");
        //        return -1;
        //    }
        //    finally
        //    {
        //        sqlHelper.Dispose();
        //    }
        //}

        /// <summary>
        /// 重置错误数据
        /// </summary>
        /// <param name="jobPara"></param>
        /// <param name="dsData"></param>
        /// <returns></returns>
        public async Task<int> ResetError(JobPara jobPara, List<Datas> dsData)
        {
            await sqlHelper.ExecSqlAsync("delete ERRORDATA_XH_JDWMS");
            await _jobLogger.WriteLogAsync(LogType.Info, "错误的数据已重置", $"ERRORDATA_XH_JDWMS表已清空，推送错误的数据已重置");
            return 0;
        }
    }
}


//('09017399','09017401','07010289','07020580','09017174','1002-0','09015432','00000013','09017400','07010290','09015392','09015437','09017177','09015837','09015839','09015394','09015439','09017176','09015431','00000001','00000336','09017402','07010288','09015391','09017175','09015395')
